-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Sort Order "Comments History" tab comments correctly when same timestamp #34306
base: 2.4-develop
Are you sure you want to change the base?
Conversation
The `Password Reset Protection Type` option `By IP and Email` is inaccurate as the function does and `OR` lookup, not an `AND`.
The `Password Reset Protection Type` option `By IP and Email` is inaccurate as the function does and `OR` lookup, not an `AND`.
The `Password Reset Protection Type` option `By IP and Email` is inaccurate as the function does and `OR` lookup, not an `AND`.
The `Password Reset Protection Type` option `By IP and Email` is inaccurate as the function does and `OR` lookup, not an `AND`.
The `Password Reset Protection Type` option `By IP and Email` is inaccurate as the function does and `OR` lookup, not an `AND`.
The `Password Reset Protection Type` option `By IP and Email` is inaccurate as the function does and `OR` lookup, not an `AND`.
The `Password Reset Protection Type` option `By IP and Email` is inaccurate as the function does and `OR` lookup, not an `AND`.
The `Password Reset Protection Type` option `By IP and Email` is inaccurate as the function does and `OR` lookup, not an `AND`.
When time stamps are equal, sort by `entity_id`. Technically speaking this isn't perfect as well as the `entity_id`'s could come from different record sources (ie. comments and invoices). But given that they were at the exact same time this is acceptable. This at least ensures that the records from the same table are sorted accurately.
Hi @PromInc. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review. For more details, please, review the Magento Contributor Guide documentation. 🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
Force invoices to go after other records. Since the IDs don't correlate (different sources) they needed to be forced after the order was made.
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 comment
The 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 comment
The 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 entity_id
). The Processing
status should be first, then the Review
record, and lastly the Invoice
record.
The order records (Processing
and Review
) both live in table sales_order_status_history
and thus their entity_id
's are sequential and able to be sorted correctly. However the Invoice
record doesn't live in that table and will naturally have an entity_id
out of sequence.
Thus wehn the above line to sort by comment Invoice created
is omitted you get this result.
Notice that invoice if first. The sales_order_status_history
will typically contain more than one record per order thus those entity_id
's should always be greater than the entity_id
coming from table sales_invoice
. So this should be a safe assumption/method to detect how to put the invoice AFTER the order information. (not perfect, but given the mis-matched information should suffice)
Once this if block is added, the Invoice
record is now sorted after the Order
records as it should be and we get the proper depiction of history as it should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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:
- order history
foreach ($order->getAllStatusHistory() as $orderComment) { - credit memo history
foreach ($order->getCreditmemosCollection() as $_memo) { - shipment history
foreach ($order->getShipmentsCollection() as $_shipment) { - invoice history
foreach ($order->getInvoiceCollection() as $_invoice) { - tracking numbers history
foreach ($order->getTracksCollection() as $_track) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the method sortHistoryByTimestamp
isn't designed to sort records differently than by timestamps.
So I think a better solution there would be adding a new private method, sortHistory
, that will do the following:
- call
sortHistoryByTimestamp
to compare timestamps (for backward compatibility) - if the timestamp comparison result is the same for two records - try to compare by record type (see list above).
Note: for easier comparison - I think we might introduce private constants and pass them to the "history" array like this:
private const HISTORY_TYPE_ORDER = 1;
private const HISTORY_TYPE_CREDIT_MEMO = 2;
private const HISTORY_TYPE_SHIPMENT = 3;
private const HISTORY_TYPE_INVOICE = 4;
private const HISTORY_TYPE_TRACKING_NUM = 5;
- if the record type comparison result is the same for two records - compare by entity_id.
What do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right that comparing entity_id
for different entity types. That is a flaw in my proposed solution - I'll admit that. Theoretically it shouldn't be an issue, but wise to program to avoid it.
we should sort the records with the same time in the following order, similar as they're added:
Isn't the order of the functions you outlined the same as it currently is? And yet the issue exists?
- You bring up a good point about the function naming and what it does. I'm open to the final solution using a different function name.
- I'm not fully following the need for the new constants. I think seeing them in code might help me to better understand your intention.
- This makes sense to me.
app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php
Outdated
Show resolved
Hide resolved
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
With respect to previous build failure, all the failed tests mentioned in comment are working fine now. There are some static test failures right now. Looking into that. |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
@magento run Unit Tests, Functional Tests B2B , Functional Tests CE, Functional Tests EE |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
@magento run Unit Tests, Functional Tests B2B , Functional Tests CE, Functional Tests EE |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
Fixed failing static as well as some functional test cases. Now the test case which is failing(AdminCheckVATNumberValidationButtonForEUCountryTest) in build is not part of this PR or not failing because of any changes made in this PR. As mentioned in comment requesting for the review, hence moving it to review status. Thank you! |
Sort comment history on the admin order Comments History tab by
entity_id
if the timestamps are the exact same second.Description (*)
Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
sales_order_status_history
table with the exact same timestamp.created_at
andentity_id
Questions or comments
Contribution checklist (*)