1

Let me know how to get Shipping rates Programmatically, I tried with default collectrates(), Still it's not working.

2

This will help you

     $quote = $this->checkoutSession->getQuote();
     $address = $quote->getShippingAddress();
     $address->collectShippingRates();
  • If i have to print the rates, Do i have to call any function? – Nagamani May 21 '18 at 6:59
  • you have to pass quote id. – Vishnunath May 21 '18 at 7:18
  • 1
    foreach ($address->getAllShippingRates() as $rate) { $shippingAmount += $rate->getPrice(); }, It worked after this piece of code. – Nagamani May 21 '18 at 7:23
  • There is some way to get the quotation without a checkout session object? I'm trying to get it on product page ... – lpFranz Sep 4 '18 at 14:56
  • @Vishnunath, can we apply particular table_rate for the address? – jafar pinjar Aug 22 at 14:32
0

Please find the sample code below for getting shipping rates. you have to pass quoteId

    use Magento\Framework\App\Bootstrap;

    require dirname(__FILE__) . '/../app/bootstrap.php';

    $bootstrap = Bootstrap::create(BP, $_SERVER);

    $obj = $bootstrap->getObjectManager();

    $state = $obj->get('Magento\Framework\App\State');
    $state->setAreaCode('frontend');

    $quote = $obj->get('Magento\Checkout\Model\Session')->getQuote()->load(1);
    $address = $quote->getShippingAddress();
    $address->collectShippingRates();
    print_r($address->getData());
    //print_r($quote->getOrigData());

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.