Magento facing issues with Setting Shipping Method to Quote
-
07-10-2020 - |
Question
I am setting Shipping Method to quote, For one particular method, shipping price is not added to quote but for other shipping methods it is working fine. Can anyone suggest on this, I have used below code,
// Collect Rates and Set Shipping & Payment Method
$quote->getShippingAddress()->setCollectShippingRates(true)->collectShippingRates();
$quote->getShippingAddress()->setShippingMethod($postParams['shipping_method']);
$quote->getShippingAddress()->setPaymentMethod($postParams['payment_method']);
//Set Sales Order Payment
$quote->getPayment()->importData(array('method' => $postParams['payment_method']));
// Collect Totals & Save Quote
$quote->collectTotals()->save();
Solution
Finally, I got it fixed by using below code,
$quote->getShippingAddress()->setCollectShippingRates(true)->collectShippingRates();
// Updated Line
$quote->getShippingAddress()->setShippingMethod($postParams['shipping_method'])->setCollectShippingRates(true);
// Updated Line
$quote->getShippingAddress()->setPaymentMethod($postParams['payment_method']);
//Set Sales Order Payment
$quote->getPayment()->importData(array('method' => $postParams['payment_method']));
// Collect Totals & Save Quote
$quote->collectTotals()->save();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange