-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Sort Order "Comments History" tab comments correctly when same timestamp #34306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.4-develop
Are you sure you want to change the base?
Changes from 22 commits
b7af8a5
242c12f
08d20be
6c87486
692f96d
4febd7c
41188db
bf1c340
ba24475
836a325
eba21cf
7947440
36a2245
e46991f
81e3cbc
c1fb73c
5174e50
c81212c
75999e0
47e17a5
1875102
f597b7a
6e79dc6
a5b81c2
a23b463
70cf0a4
4109ff2
d4c0ba5
1e8d5c6
e65dea4
451831a
5ce6523
84cd2f4
16ecc87
30a9d66
284dad8
d4d00a3
f7a746f
30dd1a4
0a9223d
496302d
fc46a6b
78c55d6
ceede4b
2ade2a7
54a7be0
170e2fb
caf892c
7130231
76e55e0
259be51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -76,6 +76,7 @@ public function getFullHistory() | |||||||||||
$history = []; | ||||||||||||
foreach ($order->getAllStatusHistory() as $orderComment) { | ||||||||||||
$history[] = $this->_prepareHistoryItem( | ||||||||||||
$orderComment->getId(), | ||||||||||||
$orderComment->getStatusLabel(), | ||||||||||||
$orderComment->getIsCustomerNotified(), | ||||||||||||
$this->getOrderAdminDate($orderComment->getCreatedAt()), | ||||||||||||
|
@@ -85,13 +86,15 @@ public function getFullHistory() | |||||||||||
|
||||||||||||
foreach ($order->getCreditmemosCollection() as $_memo) { | ||||||||||||
$history[] = $this->_prepareHistoryItem( | ||||||||||||
$_memo->getId(), | ||||||||||||
__('Credit memo #%1 created', $_memo->getIncrementId()), | ||||||||||||
$_memo->getEmailSent(), | ||||||||||||
$this->getOrderAdminDate($_memo->getCreatedAt()) | ||||||||||||
); | ||||||||||||
|
||||||||||||
foreach ($_memo->getCommentsCollection() as $_comment) { | ||||||||||||
$history[] = $this->_prepareHistoryItem( | ||||||||||||
$_comment->getId(), | ||||||||||||
__('Credit memo #%1 comment added', $_memo->getIncrementId()), | ||||||||||||
$_comment->getIsCustomerNotified(), | ||||||||||||
$this->getOrderAdminDate($_comment->getCreatedAt()), | ||||||||||||
|
@@ -102,13 +105,15 @@ public function getFullHistory() | |||||||||||
|
||||||||||||
foreach ($order->getShipmentsCollection() as $_shipment) { | ||||||||||||
$history[] = $this->_prepareHistoryItem( | ||||||||||||
$_shipment->getId(), | ||||||||||||
__('Shipment #%1 created', $_shipment->getIncrementId()), | ||||||||||||
$_shipment->getEmailSent(), | ||||||||||||
$this->getOrderAdminDate($_shipment->getCreatedAt()) | ||||||||||||
); | ||||||||||||
|
||||||||||||
foreach ($_shipment->getCommentsCollection() as $_comment) { | ||||||||||||
$history[] = $this->_prepareHistoryItem( | ||||||||||||
$_comment->getId(), | ||||||||||||
__('Shipment #%1 comment added', $_shipment->getIncrementId()), | ||||||||||||
$_comment->getIsCustomerNotified(), | ||||||||||||
$this->getOrderAdminDate($_comment->getCreatedAt()), | ||||||||||||
|
@@ -119,13 +124,16 @@ public function getFullHistory() | |||||||||||
|
||||||||||||
foreach ($order->getInvoiceCollection() as $_invoice) { | ||||||||||||
$history[] = $this->_prepareHistoryItem( | ||||||||||||
$_invoice->getId(), | ||||||||||||
__('Invoice #%1 created', $_invoice->getIncrementId()), | ||||||||||||
$_invoice->getEmailSent(), | ||||||||||||
$this->getOrderAdminDate($_invoice->getCreatedAt()) | ||||||||||||
$this->getOrderAdminDate($_invoice->getCreatedAt()), | ||||||||||||
'Invoice created' | ||||||||||||
); | ||||||||||||
|
||||||||||||
foreach ($_invoice->getCommentsCollection() as $_comment) { | ||||||||||||
$history[] = $this->_prepareHistoryItem( | ||||||||||||
$_comment->getId(), | ||||||||||||
__('Invoice #%1 comment added', $_invoice->getIncrementId()), | ||||||||||||
$_comment->getIsCustomerNotified(), | ||||||||||||
$this->getOrderAdminDate($_comment->getCreatedAt()), | ||||||||||||
|
@@ -136,6 +144,7 @@ public function getFullHistory() | |||||||||||
|
||||||||||||
foreach ($order->getTracksCollection() as $_track) { | ||||||||||||
$history[] = $this->_prepareHistoryItem( | ||||||||||||
$_track->getId(), | ||||||||||||
__('Tracking number %1 for %2 assigned', $_track->getNumber(), $_track->getTitle()), | ||||||||||||
false, | ||||||||||||
$this->getOrderAdminDate($_track->getCreatedAt()) | ||||||||||||
|
@@ -303,6 +312,13 @@ public static function sortHistoryByTimestamp($a, $b) | |||||||||||
{ | ||||||||||||
$createdAtA = $a['created_at']; | ||||||||||||
$createdAtB = $b['created_at']; | ||||||||||||
|
||||||||||||
if( $createdAtA->getTimestamp() === $createdAtB->getTimestamp() ) { | ||||||||||||
PromInc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
if( $a['comment'] == 'Invoice created' || $b['comment'] == 'Invoice created' ) { | ||||||||||||
return ( $a['comment'] == 'Invoice created' ? 1 : -1 ); | ||||||||||||
} | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain why do we need to have this if block? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course! Here is an example screenshot of when the bug exists. There are 3 records that occurred at the exact same time. But they are out of order. We know from the codebase that Magento creates the order first and then the invoice. So it makes sense that the order statuses are listed first and then the invoice record is last. Because I use the Kount module, it created 2 records about the order status at the exact same time and are not sorted correctly (based on The order records ( Thus wehn the above line to sort by comment Notice that invoice if first. The Once this if block is added, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. It was still unclear that order history records are shown from older to newer from top to bottom. The issue makes sense to me, but I'm afraid I have to disagree with the implementation. It doesn't make any sense to compare the entity_id of order and shipment records, but it makes sense competing for two records of the same type. As for me, we should sort the records with the same time in the following order, similar as they're added:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the method So I think a better solution there would be adding a new private method,
What do you think about it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right that comparing
|
||||||||||||
return $a['entity_id'] <=> $b['entity_id']; | ||||||||||||
} | ||||||||||||
|
||||||||||||
return $createdAtA->getTimestamp() <=> $createdAtB->getTimestamp(); | ||||||||||||
} | ||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.