/** * Create order * * @param \Magento\Sales\Service\V1\Data\Order $orderDataObject * @return bool * @throws \Exception */ public function invoke(\Magento\Sales\Service\V1\Data\Order $orderDataObject) { try { $order = $this->orderConverter->getModel($orderDataObject); return (bool) $order->save(); } catch (\Exception $e) { $this->logger->logException($e); throw new \Exception(__('An error has occurred during order creation')); } }
public function testGetModel() { $billingAddressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', ['__wakeup'], [], '', false); $shippingAddressMock = clone $billingAddressMock; $this->addressConverterMock->expects($this->at(0))->method('getModel')->with($this->orderData['billingAddress'])->will($this->returnValue($billingAddressMock)); $this->addressConverterMock->expects($this->at(1))->method('getModel')->with($this->orderData['shippingAddress'])->will($this->returnValue($shippingAddressMock)); $this->orderBuilderMock->expects($this->once())->method('setCustomer')->with($this->getCustomer())->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setQuoteId')->with($this->orderData['quoteId'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setAppliedRuleIds')->with($this->orderData['appliedRuleIds'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setIsVirtual')->with($this->orderData['isVirtual'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setRemoteIp')->with($this->orderData['remoteIp'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setBaseSubtotal')->with($this->orderData['baseSubtotal'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setSubtotal')->with($this->orderData['subtotal'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setBaseGrandTotal')->with($this->orderData['baseGrandTotal'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setGrandTotal')->with($this->orderData['grandTotal'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setBaseCurrencyCode')->with($this->orderData['baseCurrencyCode'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setGlobalCurrencyCode')->with($this->orderData['globalCurrencyCode'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setStoreCurrencyCode')->with($this->orderData['storeCurrencyCode'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setStoreId')->with($this->orderData['storeId'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setStoreToBaseRate')->with($this->orderData['storeToBaseRate'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setBaseToGlobalRate')->with($this->orderData['baseToGlobalRate'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setCouponCode')->with($this->orderData['couponCode'])->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setBillingAddress')->with($billingAddressMock)->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setShippingAddress')->with($shippingAddressMock)->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setPayments')->with($this->getPayments())->will($this->returnSelf()); $this->orderBuilderMock->expects($this->once())->method('setItems')->with($this->getItems())->will($this->returnSelf()); $orderMock = $this->getMock('Magento\\Sales\\Model\\Order', [], [], '', false); $this->orderBuilderMock->expects($this->once())->method('create')->will($this->returnValue($orderMock)); $this->assertEquals($orderMock, $this->orderConverter->getModel($this->orderDataMock)); }