I'm creating quote / order programmaticaly. But when I do this, I have an exception : (in english, "select shipping method")
Magento\Framework\Exception\LocalizedException: Sélectionnez un mode de livraison.
However, on my localhost, I can create quote / order. See my code :
$quote=$this->quote->create(); //Create object of quote
$quote->setStore($store); //set store for which you create quote
$customer= $this->customerRepository->getById($customer->getEntityId());
$quote->setCurrency();
$quote->assignCustomer($customer); //Assign quote to customer
//add items in quote
foreach($orderData['items'] as $item){
$product = $this->getProduct($item['product_id']);
// $product->setPrice($item['price']);
$product->setPrice(0);
$quote->addProduct(
$product,
intval($item['qty'])
);
}
//Set Address to quote
$quote->getBillingAddress()->addData($orderData['shipping_address']);
$quote->getShippingAddress()->addData($orderData['shipping_address']);
// Collect Rates and Set Shipping & Payment Method
$shippingAddress=$quote->getShippingAddress();
//set shipping method is not working
$shippingAddress->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod('freeshipping_freeshipping'); //shipping method
$quote->setPaymentMethod('checkmo'); //payment method
$quote->setInventoryProcessed(false); //not effetc inventory
$this->quoteRepository->save($quote);
// $quote->save(); //Now Save quote and your quote is ready
// Set Sales Order Payment
$quote->getPayment()->importData(['method' => 'checkmo']);
// Collect Totals & Save Quote
$quote->collectTotals();
$this->quoteRepository->save($quote);
// Create Order From Quote (exception here)
$order = $this->quoteManagement->submit($quote);