2

I have a special case where I want to show all active shipping methods with applied estimated shipping cost to login customer if customer has default shipping address set in address book.

The following link describe how to show all active shipping methods in a custom module.

Magento 2 How to get all active shipping methods?

But I did not find any code that also display shipping rate of each method. So I need to show shipping rate of each shipping method to login customer. These customer already has some shipping address.

0

I just create some code hopefully its help u.

create test.php on your project root directory.

require __DIR__. '/app/bootstrap.php'; 

require __DIR__.'/TestApp.php';

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager(); /** @var
\Magento\Framework\App\State $state */ $state =
$obj->get(\Magento\Framework\App\State::class);
$state->setAreaCode('frontend');

/** @var \Magento\Framework\App\Http $app */ $app =
$bootstrap->createApplication(TestApp::class);

$bootstrap->run($app);

Then create TestApp.php on your project root directory.

use Magento\Shipping\Model\Config\Source\Allmethods;

class TestApp extends \Magento\Framework\App\Http implements
\Magento\Framework\AppInterface {

    public function launch() {
        /** @var \Magento\Shipping\Model\Config\Source\Allmethods $allmethods */
        $allmethods = $this->_objectManager->get(Allmethods::class);

        echo"<pre>";
        print_r($allmethods->toOptionArray());

        return $this->_response;
    }

}
  • $allmethods->toOptionArray() only return shipping methods, I need shipping rates of each method also, and I am stuck on how to get shipping rates along with shipping methods – Waseem Abbas Mar 14 '18 at 14:33

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.