-
Notifications
You must be signed in to change notification settings - Fork 169
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
How to require shipping tracking code when changing order status to shipped #1244
Comments
@lukeholder that trello link is telling me that the card is not found |
Sorry @moldedjelly we were testing an integration. The order status change should not be cancellable, that is a bug, sorry about that. Will be fixed in the next release. In commerce 3, you should hook into the beforeValidate order event and add a validation error to the order if they are trying to save the order with a different status ID (and they have no trackingCode present). You would need to do a query of the order from the DB to get the current status ID and compare it to the new status ID. |
so I updated my code as below which seems to work and gives a very general error at top of CP order edit page: "The order is not valid". The only thing is, it doesn't present the error on the trackingCode field - but it does show at base of "Order Details" tab as red JSON - should it be showing the error on the field?
|
Hi @moldedjelly You would use |
@lukeholder thanks for the help on this. I updated my code as you suggested. It still doesn't present the error on the field though - it presents the error at base of Order Details tab screenshot here |
Hi @moldedjelly We are currently working on updates to the Order Edit screen for Thanks. |
Description
I'm trying to use the orderStatusChange event to detect when changing the order status to shipped, to then check if a shipping code has been supplied
This is my code:
Event::on(OrderHistories::class, OrderHistories::EVENT_ORDER_STATUS_CHANGE, function(OrderStatusEvent $e) {
$order = $e->order;
if (empty($order->trackingCode)) {
$e->isValid = false;
// would be nice to also show an error with feedback?
}
});
Looking at the OrderStatusEvent class, it appears to extend CancelableEvent so should be able to do this?
How might I also provide some feedback too?
The text was updated successfully, but these errors were encountered: