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();
$shippingAddress->setCollectShippingRates(true);
if ($shippingMethod === 'tablerates' ||
$this->_moduleManager->isDhlInstalled() === false) {
$shippingAddress->setShippingMethod('tablerate_bestway');
} else {
$shippingAddress->setShippingMethod('dhlrates_DOM');
}
/*
* NEXT 2 LINES ONLY FOR TESTING!
*/
$shippingAddress->save();
$quote->setShippingAddress($shippingAddress);
$quote->getPayment()->importData(['method' => 'checkmo']);
$quote->setInventoryProcessed(false);
/*
* Added setTotalsCollectedFlag(false) for testing
*/
$this->_quoteResource->save($quote->setTotalsCollectedFlag(false)->collectTotals());
//$rates = $shippingAddress->collectShippingRates()
// ->getGroupedAllShippingRates();
$order = $this->_quoteManagement->submit($quote, $orderData);