/** * Creates a sample order * * @throws \Magento\Framework\Exception\LocalizedException */ public function createOrder() { $store = $this->storeManager->getStore(); $websiteId = $this->storeManager->getStore()->getWebsiteId(); $customer = $this->getCustomer(); $repositoryCustomer = $this->customerRepository->getById($customer->getId()); $quote = $this->quoteFactory->create(); $quote->setStore($store); $quote->assignCustomer($repositoryCustomer); $this->addItemsToQuote($quote); $quote->getBillingAddress()->addData($this->orderSampleData['address']); $quote->getShippingAddress()->addData($this->orderSampleData['address']); $this->addressRate->setCode(self::ORDER_SHIPPING_METHOD_CODE); $this->addressRate->getPrice(1); $shippingAddress = $quote->getShippingAddress(); $shippingAddress->addShippingRate($this->addressRate); $shippingAddress->setCollectShippingRates(true)->collectShippingRates()->setShippingMethod(self::ORDER_SHIPPING_METHOD_CODE); $quote->setPaymentMethod(self::ORDER_PAYMENT_METHOD_CODE); $quote->setInventoryProcessed(false); $quote->save(); $quote->getPayment()->importData(['method' => self::ORDER_PAYMENT_METHOD_CODE]); $quote->collectTotals()->save(); $order = $this->quoteManagement->submit($quote); $order->setEmailSent(0); }