Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InvoiceDocumentFactory.php
Go to the documentation of this file.
1 <?php
8 
15 
23 {
27  private $invoiceService;
28 
33  public function __construct(
34  InvoiceService $invoiceService
35  ) {
36  $this->invoiceService = $invoiceService;
37  }
38 
49  public function create(
51  $items = [],
52  InvoiceCommentCreationInterface $comment = null,
53  $appendComment = false,
55  ) {
56  $invoiceItems = $this->itemsToArray($items);
57  $invoice = $this->invoiceService->prepareInvoice($order, $invoiceItems);
58 
59  if ($comment) {
60  $invoice->addComment(
61  $comment->getComment(),
62  $appendComment,
63  $comment->getIsVisibleOnFront()
64  );
65  }
66 
67  return $invoice;
68  }
69 
76  private function itemsToArray($items = [])
77  {
78  $invoiceItems = [];
79  foreach ($items as $item) {
80  $invoiceItems[$item->getOrderItemId()] = $item->getQty();
81  }
82  return $invoiceItems;
83  }
84 }
$order
Definition: order.php:55
$invoice
$invoiceService
$arguments
create(OrderInterface $order, $items=[], InvoiceCommentCreationInterface $comment=null, $appendComment=false, InvoiceCreationArgumentsInterface $arguments=null)
$items