How to calculate and store shipping rate in Magento 2.3.0?
-
14-04-2021 - |
سؤال
I'm using Magento v 2.3.0.
I am trying to skip Shipping Address section and navigate directly to Payment section if customer has a default address.
I have overridden below class to change the link of checkout url
Magento\Checkout\Block\Onepage\Link
Function overridden
getCheckoutUrl
Now I also use the checkout session in above overridden class to get the quote and set the shipping address in it.
I use tablerate_bestway as shipping method.
How do I set the shipping method and recalculate the shipping rate and save it in the quote?
المحلول
After set the shipping address in quote use below code to set shipping method programatically
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod('shippingMethod') //shipping method
->setShippingDescription('shipping method description'); //shipping description
$quote->save();
لا تنتمي إلى magento.stackexchange