Let me know how to get Shipping rates Programmatically, I tried with default collectrates()
, Still it's not working.
This will help you
$quote = $this->checkoutSession->getQuote();
$address = $quote->getShippingAddress();
$address->collectShippingRates();
-
-
-
1foreach ($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
-
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());