Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
creditmemo_comments_for_search.php
Go to the documentation of this file.
1 <?php
12 
13 require 'default_rollback.php';
14 require __DIR__ . '/order.php';
15 
17 $order = Bootstrap::getObjectManager()->create(Order::class);
18 $order->loadByIncrementId('100000001');
19 
21 $creditmemoFactory = Bootstrap::getObjectManager()->get(CreditmemoFactory::class);
22 
24 $creditmemo = $creditmemoFactory->createByOrder($order, $order->getData());
25 $creditmemo->setOrder($order);
26 $creditmemo->setState(Creditmemo::STATE_OPEN);
27 $creditmemo->setIncrementId('100000001');
28 $creditmemo->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 
58 foreach ($comments as $data) {
60  $comment = Bootstrap::getObjectManager()->create(Comment::class);
61  $comment->setParentId($creditmemo->getId());
62  $comment->setComment($data['comment']);
63  $comment->setIsVisibleOnFront($data['is_visible_on_front']);
64  $comment->setIsCustomerNotified($data['is_customer_notified']);
65  $comment->save();
66 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60