Esempio n. 1
0
 /**
  * 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, []));
 }
Esempio n. 2
0
 /**
  * @param Item|AddressItem $item
  * @param array $data
  * @return OrderItemInterface
  */
 public function convert($item, $data = [])
 {
     $options = $item->getProductOrderOptions();
     if (!$options) {
         $options = $item->getProduct()->getTypeInstance()->getOrderOptions($item->getProduct());
     }
     $orderItemData = $this->objectCopyService->getDataFromFieldset('quote_convert_item', 'to_order_item', $item);
     if (!$item->getNoDiscount()) {
         $data = array_merge($data, $this->objectCopyService->getDataFromFieldset('quote_convert_item', 'to_order_item_discount', $item));
     }
     $orderItem = $this->orderItemFactory->create();
     $this->dataObjectHelper->populateWithArray($orderItem, array_merge($orderItemData, $data), '\\Magento\\Sales\\Api\\Data\\OrderItemInterface');
     $orderItem->setProductOptions($options);
     if ($item->getParentItem()) {
         $orderItem->setQtyOrdered($orderItemData[OrderItemInterface::QTY_ORDERED] * $item->getParentItem()->getQty());
     }
     return $orderItem;
 }