/** * test for convert method */ public function testConvert() { $this->quoteItemMock->expects($this->exactly(2))->method('getProduct')->willReturn($this->productMock); $this->productMock->expects($this->once())->method('getTypeInstance')->willReturn($this->productTypeMock); $this->productTypeMock->expects($this->once())->method('getOrderOptions')->with($this->productMock)->willReturn(['option']); $this->objectCopyServiceMock->expects($this->at(0))->method('getDataFromFieldset')->with('quote_convert_item', 'to_order_item', $this->quoteItemMock)->willReturn([]); $this->objectCopyServiceMock->expects($this->at(1))->method('getDataFromFieldset')->with('quote_convert_item', 'to_order_item_discount', $this->quoteItemMock)->willReturn([]); $this->orderItemFactoryMock->expects($this->once())->method('create')->willReturn($this->orderItemMock); $this->assertInstanceOf('Magento\\Sales\\Model\\Order\\Item', $this->converter->convert($this->quoteItemMock, [])); }
public function testSubmit() { $orderData = []; $isGuest = true; $isVirtual = false; $customerId = 1; $quoteId = 1; $quoteItem = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', [], [], '', false); $billingAddress = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', [], [], '', false); $shippingAddress = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', [], [], '', false); $payment = $this->getMock('Magento\\Quote\\Model\\Quote\\Payment', [], [], '', false); $baseOrder = $this->getMock('Magento\\Sales\\Api\\Data\\OrderInterface', [], [], '', false); $convertedBillingAddress = $this->getMock('Magento\\Sales\\Api\\Data\\OrderAddressInterface', [], [], '', false); $convertedShippingAddress = $this->getMock('Magento\\Sales\\Api\\Data\\OrderAddressInterface', [], [], '', false); $convertedPayment = $this->getMock('Magento\\Sales\\Api\\Data\\OrderPaymentInterface', [], [], '', false); $convertedQuoteItem = $this->getMock('Magento\\Sales\\Api\\Data\\OrderItemInterface', [], [], '', false); $addresses = [$convertedShippingAddress, $convertedBillingAddress]; $payments = [$convertedPayment]; $quoteItems = [$quoteItem]; $convertedItems = [$convertedQuoteItem]; $quote = $this->getQuote($isGuest, $isVirtual, $billingAddress, $payment, $customerId, $quoteId, $quoteItems, $shippingAddress); $this->quoteValidator->expects($this->once())->method('validateBeforeSubmit')->with($quote); $this->quoteAddressToOrder->expects($this->once())->method('convert')->with($shippingAddress, $orderData)->willReturn($baseOrder); $this->quoteAddressToOrderAddress->expects($this->at(0))->method('convert')->with($shippingAddress, ['address_type' => 'shipping', 'email' => '*****@*****.**'])->willReturn($convertedShippingAddress); $this->quoteAddressToOrderAddress->expects($this->at(1))->method('convert')->with($billingAddress, ['address_type' => 'billing', 'email' => '*****@*****.**'])->willReturn($convertedBillingAddress); $this->quoteItemToOrderItem->expects($this->once())->method('convert')->with($quoteItem, ['parent_item' => null])->willReturn($convertedQuoteItem); $this->quotePaymentToOrderPayment->expects($this->once())->method('convert')->with($payment)->willReturn($convertedPayment); $order = $this->prepareOrderFactory($baseOrder, $convertedBillingAddress, $addresses, $payments, $convertedItems, $quoteId, $convertedShippingAddress); $this->orderManagement->expects($this->once())->method('place')->with($order)->willReturn($order); $this->eventManager->expects($this->at(0))->method('dispatch')->with('sales_model_service_quote_submit_before', ['order' => $order, 'quote' => $quote]); $this->eventManager->expects($this->at(1))->method('dispatch')->with('sales_model_service_quote_submit_success', ['order' => $order, 'quote' => $quote]); $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quote); $this->assertEquals($order, $this->model->submit($quote, $orderData)); }
/** * {@inheritdoc} */ public function convert($item, $data = array()) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'convert'); if (!$pluginInfo) { return parent::convert($item, $data); } else { return $this->___callPlugins('convert', func_get_args(), $pluginInfo); } }
/** * @param Quote $quote * @return array */ protected function resolveItems(QuoteEntity $quote) { $quoteItems = $quote->getAllItems(); $orderItems = []; foreach ($quoteItems as $quoteItem) { $parentItem = isset($orderItems[$quoteItem->getParentItemId()]) ? $orderItems[$quoteItem->getParentItemId()] : null; $orderItems[$quoteItem->getId()] = $this->quoteItemToOrderItem->convert($quoteItem, ['parent_item' => $parentItem]); } return array_values($orderItems); }
/** * @param Quote $quote * @return array */ protected function resolveItems(QuoteEntity $quote) { $quoteItems = []; foreach ($quote->getAllItems() as $quoteItem) { /** @var \Magento\Quote\Model\Resource\Quote\Item $quoteItem */ $quoteItems[$quoteItem->getId()] = $quoteItem; } $orderItems = []; foreach ($quoteItems as $quoteItem) { $parentItem = isset($orderItems[$quoteItem->getParentItemId()]) ? $orderItems[$quoteItem->getParentItemId()] : null; $orderItems[$quoteItem->getId()] = $this->quoteItemToOrderItem->convert($quoteItem, ['parent_item' => $parentItem]); } return array_values($orderItems); }
/** * @param Quote $quote * @return array */ protected function resolveItems(QuoteEntity $quote) { $quoteItems = $quote->getAllItems(); for ($i = 0; $i < count($quoteItems) - 1; $i++) { for ($j = 0; $j < count($quoteItems) - $i - 1; $j++) { if ($quoteItems[$i]->getParentItemId() == $quoteItems[$j]->getId()) { $tempItem = $quoteItems[$i]; $quoteItems[$i] = $quoteItems[$j]; $quoteItems[$j] = $tempItem; } } } $orderItems = []; foreach ($quoteItems as $quoteItem) { $parentItem = isset($orderItems[$quoteItem->getParentItemId()]) ? $orderItems[$quoteItem->getParentItemId()] : null; $orderItems[$quoteItem->getId()] = $this->quoteItemToOrderItem->convert($quoteItem, ['parent_item' => $parentItem]); } return array_values($orderItems); }
/** * Prepare order based on quote address * * @param \Magento\Quote\Model\Quote\Address $address * @return \Magento\Sales\Model\Order * @throws \Magento\Checkout\Exception */ protected function _prepareOrder(\Magento\Quote\Model\Quote\Address $address) { $quote = $this->getQuote(); $quote->unsReservedOrderId(); $quote->reserveOrderId(); $quote->collectTotals(); $order = $this->quoteAddressToOrder->convert($address); $order->setQuote($quote); $order->setBillingAddress($this->quoteAddressToOrderAddress->convert($quote->getBillingAddress())); if ($address->getAddressType() == 'billing') { $order->setIsVirtual(1); } else { $order->setShippingAddress($this->quoteAddressToOrderAddress->convert($address)); } $order->setPayment($this->quotePaymentToOrderPayment->convert($quote->getPayment())); if ($this->priceCurrency->round($address->getGrandTotal()) == 0) { $order->getPayment()->setMethod('free'); } foreach ($address->getAllItems() as $item) { $_quoteItem = $item->getQuoteItem(); if (!$_quoteItem) { throw new \Magento\Checkout\Exception(__('Item not found or already ordered')); } $item->setProductType($_quoteItem->getProductType())->setProductOptions($_quoteItem->getProduct()->getTypeInstance()->getOrderOptions($_quoteItem->getProduct())); $orderItem = $this->quoteItemToOrderItem->convert($item); if ($item->getParentItem()) { $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId())); } $order->addItem($orderItem); } return $order; }