- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2018
01:33 PM
02-26-2018
01:33 PM
Create Order with tablerates
I'm trying to place an order programmatically with tablerates. Here is my code
```
$quote->getShippingAddress()->addData($postData['shipping_address']);
$quote->getBillingAddress()->addData($postData['billing_address']);
/** @var \Magento\Quote\Model\Quote\Address $shippingAddress */
$shippingAddress= $quote->getShippingAddress();
$shippingAddress
->removeAllShippingRates()
->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod('tablerate_bestway') //shipping method
->setShippingDescription('Table Rate - Best Way');
$this->handlePayment('banktransfer');
$quote->setPayment($this->payment);
$quote->setCheckoutMethod(QuoteManagement::METHOD_GUEST);
$quote->save();
$quote->collectTotals();
$orderId = $this->cartManagement->placeOrder($quote->getId());
$order = $this->orderResource->load($this->order, $orderId);
```
I'm constantly getting *** Please specify a shipping method***. In QuoteValidator it trie€ to get the rate $rate = $quote->getShippingAddress()->getShippingRateByCode($method); which always returns false. tablerates is setup as I can use this when placing an Order with the Rest api
how can I place this order with tablerates prgrammatically?
```
$quote->getShippingAddress()->addData($postData['shipping_address']);
$quote->getBillingAddress()->addData($postData['billing_address']);
/** @var \Magento\Quote\Model\Quote\Address $shippingAddress */
$shippingAddress= $quote->getShippingAddress();
$shippingAddress
->removeAllShippingRates()
->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod('tablerate_bestway') //shipping method
->setShippingDescription('Table Rate - Best Way');
$this->handlePayment('banktransfer');
$quote->setPayment($this->payment);
$quote->setCheckoutMethod(QuoteManagement::METHOD_GUEST);
$quote->save();
$quote->collectTotals();
$orderId = $this->cartManagement->placeOrder($quote->getId());
$order = $this->orderResource->load($this->order, $orderId);
```
I'm constantly getting *** Please specify a shipping method***. In QuoteValidator it trie€ to get the rate $rate = $quote->getShippingAddress()->getShippingRateByCode($method); which always returns false. tablerates is setup as I can use this when placing an Order with the Rest api
how can I place this order with tablerates prgrammatically?
Labels:
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2018
01:49 PM
03-03-2018
01:49 PM
Re: Create Order with tablerates
Hi @pcamper,
Maybe you could check this post: https://webkul.com/blog/create-quote-and-order-programmatically-in-magento2/