0

I'm using Magento 2.1.3

I would like to change the order status to custom "waiting for courier" after shipping and invoice is created instead of "complete".

Right now I'm using event "sales_order_shipment_save_after" but it's not enough.

Where can I find it?

4

2 Answers 2

2

For that you do not need development. You can do this in your backend directly:

Step 1 : Add new status
- In Stores > Settings > Order Status
- Create new status
- Status code : waiting_for_courier
- Status label : Waiting for courier
- Save status

Step 2 : Assign status to state
- Assign Status to State button
- Order status : Waiting for courier
- Order state : Complete
- Use Order Status As Default : Yes => important
- Visible On Storefront : Yes - Save Status Assignment

With that you defined the waiting_for_courier status as the new defaut complete state status instead of complete.

If you want more informations about status / state management here is a article about that : http://www.magestore.com/magento-2-tutorial/manage-order-status-in-magento-2/

6
  • Thanks :) It help me a lot and almost works. There is one problem - I don't want set state complete yet. I need to set state 'complete' after package is delivered to customer. Jan 23, 2017 at 10:19
  • What is triggering the change from waiting for courier to complete ? Is that the shipment is completed ? How do you have this information ? Jan 23, 2017 at 10:22
  • Couriers Api provide this information Jan 23, 2017 at 11:25
  • In this case you can do this : use my answer solution and then at the API response you can set the complete status to the order. Depeding on your other developments but the fact that both of the status are with the state complete is not an issue. It is native that Magento set complete state when the invoice and shipment are created. Jan 23, 2017 at 12:10
  • Is that OK for you ? Jan 24, 2017 at 13:15
0

Create around plugin on Magento\Sales\Model\ResourceModel\Order\Handler\State:Check method something like below

public function aroundCheck(State $subject, callable $proceed, Order $order)
{
    $shipping = $order->getShippingMethod();
    $needChange = $order->getState() === Order::STATE_PROCESSING && $shipping === Carrier::SHIPPING_CODE; // check if my custom shipping method used
    $result =  $proceed($order);
    if ($order->getState() === Order::STATE_COMPLETE && $needChange) {
        $order->setStatus('my_custom_status_assigned_to_complete_state');
    }

    return $result;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.