0

Short Story :

I'm currently working on a custom shipping method and I don't know how to execute some code when the admin submits a shipment.

Long Story :

I'm working on a custom shipping method which uses an external API to check if the client shipping address and products dimension are eligibile for the company transport service. Moreover, this custom shipping method calculates the shipping price based on the distance from the pickup place and the delivery place.

This part is done.

Now, I have to send another API call in order to book the shipping when the admin submit a shipment to an order (of course, I need to do that only when the order uses my custom shipping method). How can I execute some code when the admin hit the button ? I suppose an event can help me but I don't know which one.

Thanks for the help.

1

Found it.

I had to override the register() method in the class \Magento\Sales\Model\Order\Shipment .

0

Create an observer for sales_order_shipment_save_after event.

From your execute(EventObserver $observer) method call your custom shipping model's appropriate method.

Pass $observer object to your method.

From your shipping model you can get order collection and shipping collection as follows,

$order = $observer->getEvent()->getOrder();
$shipment = $observer->getEvent()->getShipment();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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