I would like to get the selected shipping method from the checkout page it looks like this one :

enter image description here

I just want to get the selected shipping method like above image shown : Shipping Table Rates so that I can get the shipping code method.

I have some clue to get it using \Magento\Checkout\Api\Data\ShippingInformationInterfaceFactory but when I add this to my block class I got this error :

Fatal error: Uncaught TypeError: Argument 3 passed to Fabelio\Checkout\Block\ExpectedDelivery::__construct() must be an instance of Magento\Checkout\Api\Data\ShippingInformationInterfaceFactory

Is this the correct way to getting the shipping method from checkout page ?

  • You should remove old files from the var/generation/ directory. – Siarhey Uchukhlebau Sep 29 '17 at 13:55
  • @SiarheyUchukhlebau nope not working – Gujarat Santana Sep 29 '17 at 14:28

You can do this by calling the Magento\Quote\Api\Data\ShippingMethodInterface. Add it to your constructor and get it by using this code :

 protected $shippingMethod;

public function __construct(ShippingMethodInterface $shippingMethod){
    $this->shippingMethod = $shippingMethod;

// call you code in the methos somewehre like this : 
$methodTitle = $this->shippingMethod->getMethodTitle();
|improve this answer|||||

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.