Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
invoice_comments_for_search.php
Go to the documentation of this file.
1 <?php
14 
15 require 'default_rollback.php';
16 require __DIR__ . '/order.php';
17 
19 $orderService = Bootstrap::getObjectManager()->create(InvoiceManagementInterface::class);
21 $invoice = $orderService->prepareInvoice($order);
22 $invoice->register();
24 $order = $invoice->getOrder();
25 $order->setIsInProcess(true);
27 $transactionSave = Bootstrap::getObjectManager()->create(Transaction::class);
28 $transactionSave->addObject($invoice)->addObject($order)->save();
29 
31  [
32  'comment' => 'comment 1',
33  'is_visible_on_front' => 1,
34  'is_customer_notified' => 1,
35  ],
36  [
37  'comment' => 'comment 2',
38  'is_visible_on_front' => 1,
39  'is_customer_notified' => 1,
40  ],
41  [
42  'comment' => 'comment 3',
43  'is_visible_on_front' => 1,
44  'is_customer_notified' => 1,
45  ],
46  [
47  'comment' => 'comment 4',
48  'is_visible_on_front' => 1,
49  'is_customer_notified' => 1,
50  ],
51  [
52  'comment' => 'comment 5',
53  'is_visible_on_front' => 0,
54  'is_customer_notified' => 1,
55  ],
56 ];
57 
59 $commentRepository = Bootstrap::getObjectManager()->get(InvoiceCommentRepositoryInterface::class);
60 
61 foreach ($comments as $data) {
63  $comment = Bootstrap::getObjectManager()->create(Comment::class);
64  $comment->setParentId($invoice->getId());
65  $comment->setComment($data['comment']);
66  $comment->setIsVisibleOnFront($data['is_visible_on_front']);
67  $comment->setIsCustomerNotified($data['is_customer_notified']);
68  $commentRepository->save($comment);
69 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60