Skip to content

Commit 0e07a17

Browse files
authored
Making the manual order syncer also sync cancellations and refunds, and making the pretty printer nicer (#416)
1 parent 6f006fe commit 0e07a17

File tree

2 files changed

+70
-57
lines changed

2 files changed

+70
-57
lines changed

app/code/Meta/Sales/Controller/Adminhtml/Ajax/PullOrders.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,31 @@ public function executeForJson(): array
8989
return $response;
9090
}
9191

92+
$response = [];
93+
$errors = [];
94+
9295
try {
93-
return ['success' => true, 'response' => $this->commerceHelper->pullPendingOrders((int)$storeId)];
96+
$response['synced_orders'] = $this->commerceHelper->pullPendingOrders((int)$storeId);
9497
} catch (Exception $e) {
95-
$response['success'] = false;
96-
$response['message'] = $e->getMessage();
97-
$this->fbeHelper->logExceptionImmediatelyToMeta(
98-
$e,
99-
[
100-
'store_id' => $storeId,
101-
'event' => 'order_sync',
102-
'event_type' => 'manual_sync'
103-
]
104-
);
105-
return ['success' => false, 'error_message' => $e->getMessage()];
98+
$errors['failed_orders'] = $e->getMessage();
99+
}
100+
101+
try {
102+
$response['synced_refunds'] = $this->commerceHelper->pullRefundOrders((int)$storeId);
103+
} catch (Exception $e) {
104+
$errors['failed_refunds'] = $e->getMessage();
106105
}
106+
107+
try {
108+
$response['synced_cancellations'] = $this->commerceHelper->pullCancelledOrders((int)$storeId);
109+
} catch (Exception $e) {
110+
$errors['failed_cancellations'] = $e->getMessage();
111+
}
112+
113+
return [
114+
'success' => true,
115+
'response' => $response,
116+
'errors' => $errors
117+
];
107118
}
108119
}

app/code/Meta/Sales/view/adminhtml/templates/system/config/pull_orders.phtml

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,62 @@
11
<?php /* @var $block \Meta\Sales\Block\Adminhtml\System\Config\PullOrders */ ?>
22

33
<script>
4-
require([
5-
'jquery',
6-
'prototype'
7-
], function (jQuery) {
8-
const resultBlock = jQuery('#fb_pull_orders_result');
9-
const responseToggle = jQuery('#fb_pull_orders_result_response_toggle');
10-
const responseTextBlock = jQuery('#fb_pull_orders_result_response');
4+
require([
5+
'jquery',
6+
'prototype'
7+
], function (jQuery) {
8+
const resultBlock = jQuery('#fb_pull_orders_result');
9+
const responseToggle = jQuery('#fb_pull_orders_result_response_toggle');
10+
const responseTextBlock = jQuery('#fb_pull_orders_result_response');
1111

12-
responseToggle.click(function () {
13-
responseTextBlock.toggle();
14-
});
15-
16-
jQuery('#fb_pull_orders_btn').click(function () {
17-
const params = {};
18-
new Ajax.Request('<?= $block->escapeUrl($block->getAjaxUrl()) ?>', {
19-
parameters: params,
20-
loaderArea: false,
21-
asynchronous: true,
22-
onCreate: function () {
23-
resultBlock.find('.fb-pull-orders-finished').hide();
24-
resultBlock.find('.fb-pull-orders-processing').show();
25-
jQuery('#fb_pull_orders_result_text').text('');
26-
responseToggle.hide();
27-
responseTextBlock.hide();
28-
},
29-
onSuccess: function (response) {
30-
resultBlock.find('.fb-pull-orders-processing').hide();
12+
responseToggle.click(function () {
13+
responseTextBlock.toggle();
14+
});
3115

32-
let resultText = '';
33-
let resultResponse = '';
34-
if (response.status > 200) {
35-
resultText = response.statusText;
36-
} else {
37-
resultResponse = ' (' + response.responseText + ')';
38-
resultText = 'Finished';
39-
resultBlock.find('.fb-pull-orders-finished').show();
40-
}
41-
jQuery('#fb_pull_orders_result_text').text(resultText);
42-
jQuery('#fb_pull_orders_result_response').text(resultResponse);
43-
responseToggle.show();
44-
}
45-
});
46-
});
16+
jQuery('#fb_pull_orders_btn').click(function () {
17+
const params = {};
18+
new Ajax.Request('<?= $block->escapeUrl($block->getAjaxUrl()) ?>', {
19+
parameters: params,
20+
loaderArea: false,
21+
asynchronous: true,
22+
onCreate: function () {
23+
resultBlock.find('.fb-pull-orders-finished').hide();
24+
resultBlock.find('.fb-pull-orders-processing').show();
25+
jQuery('#fb_pull_orders_result_text').text('');
26+
responseToggle.hide();
27+
responseTextBlock.hide();
28+
},
29+
onSuccess: function (response) {
30+
resultBlock.find('.fb-pull-orders-processing').hide();
4731

32+
let resultText = '';
33+
let resultResponse = '';
34+
if (response.status > 200) {
35+
resultText = response.statusText;
36+
} else {
37+
resultText = 'Finished';
38+
resultBlock.find('.fb-pull-orders-finished').show();
39+
}
40+
jQuery('#fb_pull_orders_result_text').text(resultText);
41+
let jsonObject = JSON.parse(response.responseText);
42+
let prettyJsonString = JSON.stringify(jsonObject, null, 2);
43+
jQuery('#fb_pull_orders_result_response').html('<pre style="white-space: pre-wrap;">' + prettyJsonString + '</pre>');
44+
responseToggle.show();
45+
}
46+
});
4847
});
48+
49+
});
4950
</script>
5051

51-
<?= /* @noEscape */ $block->getButtonHtml() ?>
52+
<?= /* @noEscape */
53+
$block->getButtonHtml() ?>
5254
<span id="fb_pull_orders_result">
5355
<img class="fb-pull-orders-processing" hidden="hidden" alt="Processing" style="margin:0 5px" src=
54-
"<?= $block->escapeUrl($block->getViewFileUrl('images/process_spinner.gif')) ?>"
56+
"<?= $block->escapeUrl($block->getViewFileUrl('images/process_spinner.gif')) ?>"
5557
/>
56-
<img class="fb-pull-orders-finished" hidden="hidden" alt="Finished" style="margin:-3px 5px" src=
57-
"<?= $block->escapeUrl($block->getViewFileUrl('images/rule_component_apply.gif')) ?>"
58+
<img class="fb-pull-orders-finished" hidden="hidden" alt="Finished" style="margin:-3px 5px" src=
59+
"<?= $block->escapeUrl($block->getViewFileUrl('images/rule_component_apply.gif')) ?>"
5860
/>
5961
<span id="fb_pull_orders_result_text"></span>
6062
<span id="fb_pull_orders_result_response_toggle"

0 commit comments

Comments
 (0)