-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdouble_credit_memo.php
56 lines (45 loc) · 1.52 KB
/
double_credit_memo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
ini_set('max_execution_time', 999999999);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('memory_limit', '5G');
error_reporting(E_ALL);
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/../../app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$entityTypeCode = \Magento\Catalog\Model\Product::ENTITY;
$attributeCode = 'shipping_group';
$file_name = "duplicate_credit_memo.csv";
$duplicateOrders = [];
$orderCollection = $objectManager->create('Magento\Sales\Model\ResourceModel\Order\CollectionFactory')->create();
$refundOrders = $orderCollection
->addAttributeToSelect('*')
->addFieldToFilter(
'base_total_refunded',
['gt' => 1]
);
$list = [
['orderId', 'credit memo Id']
];
foreach ($refundOrders as $_order) {
$creditMemos = $_order->getCreditmemosCollection();
if (count($creditMemos) >= 2) {
array_push($duplicateOrders, $_order->getId());
$cmIds = [];
$cmData = [];
foreach ($creditMemos as $cm) {
array_push($cmIds, $cm->getId());
}
// echo 'Order id : ' . $_order->getIncrementId() . ', credit memo id: ' . implode(", ", $cmIds) . '<br/>';
array_push($list, [$_order->getIncrementId(), implode(", ", $cmIds)]);
}
}
$file = fopen($file_name, "w");
foreach ($list as $line) {
fputcsv($file, $line);
}
fclose($file);
exit;