0

We are trying to implement a custom rate shop into our Magento store, using a custom API we developed. This API allows use to determine shipping rates in real time based on the order items and address.

I've extended the \Magento\Quote\Model\Quote\Address\Rate object and am able to update the rates we return. In order to actually get the rate from our API however I need access to the order (or I guess it would be the Quote?) object. How would I be able to get the current order (or Quote) in \Magento\Quote\Model\Quote\Address\Rate?

1 Answer 1

1

Implement a custom shipping carrier by creating a class extending \Magento\Shipping\Model\Carrier\AbstractCarrier and implementing \Magento\Shipping\Model\Carrier\CarrierInterface. Your custom carrier class should be located in the Model/Carrier directory of your module.

Extending the Rate object is not the way to go, IMO. Define your custom carrier in the di.xml file. and implement the collectRates method in your custom carrier.

see vendor/magento/module-offline-shipping for reference on how a carrier is implemented.

2
  • Thanks for your response! It got me looking into using a custom carrier instead and I found this tutorial provided by Magento: developer.adobe.com/commerce/php/tutorials/frontend/… Commented Apr 6, 2023 at 15:10
  • I was able to achieve the desired results by creating a new carrier rather than extending the rates. Thanks for pointing me in the right direction! Commented Apr 6, 2023 at 21:29

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.