3

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 ?

2
  • You should remove old files from the var/generation/ directory. Sep 29, 2017 at 13:55
  • @SiarheyUchukhlebau nope not working Sep 29, 2017 at 14:28

1 Answer 1

3

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();
1
  • I got null value @GujaratSantana Oct 29, 2020 at 6:24

Your Answer

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

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