I am struggling with a problem regarding placing an order programmatically. I have an extension that creates an order programmatically and does some stuff afterwrds (which is not relevant for my problem here).

Here is the funny thing. When the shipping address destination country is the default location, it works as expected. But if the destination country is Finland for example, I get the exception "The shipping method is missing. Select the shipping method and try again.", even if I definitiely set it, the rates have even been calculated, I checked that. But the order itself won't be submitted.

Does anyone have an idea why? I need help please...

$shippingMethod = $this->_helperData->getConfig('shipping_calculation');
$shippingAddress = $quote->getShippingAddress();

if ($shippingMethod === 'tablerates' ||
   $this->_moduleManager->isDhlInstalled() === false) {
} else {


$quote->getPayment()->importData(['method' => 'checkmo']);
 * Added setTotalsCollectedFlag(false) for testing


//$rates = $shippingAddress->collectShippingRates()
//    ->getGroupedAllShippingRates();

$order = $this->_quoteManagement->submit($quote, $orderData);

3 Answers 3


I've faced this problem. My case:

Shipping method was disabled for selected store! Double check it.


Here what I've done for this.

Replace $shippingAddress->setCollectShippingRates(true); to $quote->getShippingAddress()->setCollectShippingRates(true);

And also replace $shippingAddress->setShippingMethod('tablerate_bestway'); to $quote->getShippingAddress()->setShippingMethod('tablerate_bestway'); (depending on what shipping method you want to select. It will work.!!

  • Save the changes to quote as well.
    – TS Guhan
    Commented Mar 3, 2022 at 15:08

Try with below code:

 $shippingQuoteRate = $objectManager->get('\Magento\Quote\Model\Quote\Address\Rate');
    $shippingRateCarrier = 'freeshipping';
    $shippingRateCarrierTitle = 'Freeshipping';
    $shippingRateCode = 'freeshipping_freeshipping';
    $shippingRateMethod = 'freeshipping';
    $shippingRatePrice = '0';
    $shippingRateMethodTitle = 'Free shipping';
    $shippingAddress = $quoteFactory->getShippingAddress();
                    ->setShippingMethod($shippingRateCode); //shipping method
    $quoteFactory->setPaymentMethod('cashondelivery'); //payment method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.