-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Refactored orders/shipmentShipped method
#994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,35 +160,42 @@ Meteor.methods({ | |
| * | ||
| * @summary trigger shipmentShipped status and workflow update | ||
| * @param {Object} order - order object | ||
| * @return {Object} return workflow result | ||
| * @param {Object} shipment - shipment object | ||
| * @return {Object} return results of several operations | ||
| */ | ||
| "orders/shipmentShipped": function (order) { | ||
| "orders/shipmentShipped": function (order, shipment) { | ||
| check(order, Object); | ||
| this.unblock(); | ||
|
|
||
| if (order) { | ||
| let shipment = order.shipping[0]; | ||
| let completedItemsResult; | ||
| let completedOrderResult; | ||
|
|
||
| // Attempt to sent email notification | ||
| Meteor.call("orders/sendNotification", order); | ||
| // Attempt to sent email notification | ||
| const notifyResult = Meteor.call("orders/sendNotification", order); | ||
|
|
||
| const itemIds = shipment.items.map((item) => { | ||
| return item._id; | ||
| }); | ||
| const itemIds = shipment.items.map((item) => { | ||
| return item._id; | ||
| }); | ||
|
|
||
| Meteor.call("workflow/pushItemWorkflow", "coreOrderItemWorkflow/shipped", order, itemIds, (error) => { | ||
| // Move to completed status for items | ||
| // TODO: In the future, this could be handled by shipping delivery status | ||
| if (!error) { | ||
| Meteor.call("workflow/pushItemWorkflow", "coreOrderItemWorkflow/completed", order, itemIds, (error2) => { | ||
| // Then try to mark order as completed. | ||
| if (!error2) { | ||
| Meteor.call("workflow/pushOrderWorkflow", "coreOrderWorkflow", "completed", order); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| // TODO: In the future, this could be handled by shipping delivery status | ||
| const workflowResult = Meteor.call("workflow/pushItemWorkflow", "coreOrderItemWorkflow/shipped", order, itemIds); | ||
|
|
||
| if (workflowResult === 1) { | ||
| // Move to completed status for items | ||
| completedItemsResult = Meteor.call("workflow/pushItemWorkflow", "coreOrderItemWorkflow/completed", order, itemIds); | ||
|
|
||
| if (completedItemsResult === 1) { | ||
| // Then try to mark order as completed. | ||
| completedOrderResult = Meteor.call("workflow/pushOrderWorkflow", "coreOrderWorkflow", "completed", order); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| notify: notifyResult, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These variables should be renamed for clarity. Especially "workflow" since you aren't returning a workflow.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, any suggestions how which names could be used?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry, I don't understand. Now we have an result object: {
notify,
workflow,
completedItems,
completedOrder
}Should I rename some of these vars to
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, rename the variable |
||
| workflow: workflowResult, | ||
| completedItems: completedItemsResult, | ||
| completedOrder: completedOrderResult | ||
| }; | ||
| }, | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does
Email.sendeven return a value? And I don't think that function returns a value on error eitherThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partially it returns
true. And we could also refactororders/sendNotificationto make it return something, because I think this is important to admin to know was notification really sent or not.