-
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 42 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 | ||||
---|---|---|---|---|---|---|
|
@@ -13,6 +13,15 @@ | |||||
*/ | ||||||
class History extends \Magento\Backend\Block\Template implements \Magento\Backend\Block\Widget\Tab\TabInterface | ||||||
{ | ||||||
private const HISTORY_TYPE_INVOICE = 1; | ||||||
private const HISTORY_TYPE_INVOICE_COMMENT = 2; | ||||||
private const HISTORY_TYPE_ORDER = 3; | ||||||
private const HISTORY_TYPE_CREDIT_MEMO = 4; | ||||||
private const HISTORY_TYPE_CREDIT_MEMO_COMMENT = 5; | ||||||
private const HISTORY_TYPE_SHIPMENT = 6; | ||||||
private const HISTORY_TYPE_SHIPMENT_COMMENT = 7; | ||||||
private const HISTORY_TYPE_TRACKING_NUM = 8; | ||||||
|
||||||
/** | ||||||
* Template | ||||||
* | ||||||
|
@@ -75,74 +84,93 @@ public function getFullHistory() | |||||
|
||||||
$history = []; | ||||||
foreach ($order->getAllStatusHistory() as $orderComment) { | ||||||
$history[] = $this->_prepareHistoryItem( | ||||||
$history[] = $this->_prepareHistoryItemWithId( | ||||||
$orderComment->getId(), | ||||||
$orderComment->getStatusLabel(), | ||||||
$orderComment->getIsCustomerNotified(), | ||||||
$this->getOrderAdminDate($orderComment->getCreatedAt()), | ||||||
$orderComment->getComment() | ||||||
$orderComment->getComment(), | ||||||
self::HISTORY_TYPE_ORDER | ||||||
); | ||||||
} | ||||||
|
||||||
foreach ($order->getCreditmemosCollection() as $_memo) { | ||||||
$history[] = $this->_prepareHistoryItem( | ||||||
$history[] = $this->_prepareHistoryItemWithId( | ||||||
$_memo->getId(), | ||||||
__('Credit memo #%1 created', $_memo->getIncrementId()), | ||||||
$_memo->getEmailSent(), | ||||||
$this->getOrderAdminDate($_memo->getCreatedAt()) | ||||||
$this->getOrderAdminDate($_memo->getCreatedAt()), | ||||||
'Credit memo created', | ||||||
self::HISTORY_TYPE_CREDIT_MEMO | ||||||
); | ||||||
|
||||||
foreach ($_memo->getCommentsCollection() as $_comment) { | ||||||
$history[] = $this->_prepareHistoryItem( | ||||||
$history[] = $this->_prepareHistoryItemWithId( | ||||||
$_comment->getId(), | ||||||
__('Credit memo #%1 comment added', $_memo->getIncrementId()), | ||||||
$_comment->getIsCustomerNotified(), | ||||||
$this->getOrderAdminDate($_comment->getCreatedAt()), | ||||||
$_comment->getComment() | ||||||
$_comment->getComment(), | ||||||
self::HISTORY_TYPE_CREDIT_MEMO_COMMENT | ||||||
); | ||||||
} | ||||||
} | ||||||
|
||||||
foreach ($order->getShipmentsCollection() as $_shipment) { | ||||||
$history[] = $this->_prepareHistoryItem( | ||||||
$history[] = $this->_prepareHistoryItemWithId( | ||||||
$_shipment->getId(), | ||||||
__('Shipment #%1 created', $_shipment->getIncrementId()), | ||||||
$_shipment->getEmailSent(), | ||||||
$this->getOrderAdminDate($_shipment->getCreatedAt()) | ||||||
$this->getOrderAdminDate($_shipment->getCreatedAt()), | ||||||
self::HISTORY_TYPE_SHIPMENT | ||||||
); | ||||||
|
||||||
foreach ($_shipment->getCommentsCollection() as $_comment) { | ||||||
$history[] = $this->_prepareHistoryItem( | ||||||
$history[] = $this->_prepareHistoryItemWithId( | ||||||
$_comment->getId(), | ||||||
__('Shipment #%1 comment added', $_shipment->getIncrementId()), | ||||||
$_comment->getIsCustomerNotified(), | ||||||
$this->getOrderAdminDate($_comment->getCreatedAt()), | ||||||
$_comment->getComment() | ||||||
$_comment->getComment(), | ||||||
self::HISTORY_TYPE_SHIPMENT_COMMENT | ||||||
); | ||||||
} | ||||||
} | ||||||
|
||||||
foreach ($order->getInvoiceCollection() as $_invoice) { | ||||||
$history[] = $this->_prepareHistoryItem( | ||||||
$history[] = $this->_prepareHistoryItemWithId( | ||||||
$_invoice->getId(), | ||||||
__('Invoice #%1 created', $_invoice->getIncrementId()), | ||||||
$_invoice->getEmailSent(), | ||||||
$this->getOrderAdminDate($_invoice->getCreatedAt()) | ||||||
$this->getOrderAdminDate($_invoice->getCreatedAt()), | ||||||
'Invoice created', | ||||||
self::HISTORY_TYPE_INVOICE | ||||||
); | ||||||
|
||||||
foreach ($_invoice->getCommentsCollection() as $_comment) { | ||||||
$history[] = $this->_prepareHistoryItem( | ||||||
$history[] = $this->_prepareHistoryItemWithId( | ||||||
$_comment->getId(), | ||||||
__('Invoice #%1 comment added', $_invoice->getIncrementId()), | ||||||
$_comment->getIsCustomerNotified(), | ||||||
$this->getOrderAdminDate($_comment->getCreatedAt()), | ||||||
$_comment->getComment() | ||||||
$_comment->getComment(), | ||||||
self::HISTORY_TYPE_INVOICE_COMMENT | ||||||
); | ||||||
} | ||||||
} | ||||||
|
||||||
foreach ($order->getTracksCollection() as $_track) { | ||||||
$history[] = $this->_prepareHistoryItem( | ||||||
$history[] = $this->_prepareHistoryItemWithId( | ||||||
$_track->getId(), | ||||||
__('Tracking number %1 for %2 assigned', $_track->getNumber(), $_track->getTitle()), | ||||||
false, | ||||||
$this->getOrderAdminDate($_track->getCreatedAt()) | ||||||
$this->getOrderAdminDate($_track->getCreatedAt()), | ||||||
'Tracking number assigned', | ||||||
self::HISTORY_TYPE_TRACKING_NUM | ||||||
); | ||||||
} | ||||||
|
||||||
usort($history, [__CLASS__, 'sortHistoryByTimestamp']); | ||||||
usort($history, [__CLASS__, 'sortHistory']); | ||||||
return $history; | ||||||
} | ||||||
|
||||||
|
@@ -218,6 +246,35 @@ protected function _prepareHistoryItem($label, $notified, $created, $comment = ' | |||||
return ['title' => $label, 'notified' => $notified, 'comment' => $comment, 'created_at' => $created]; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Map history items as array with id and type | ||||||
* | ||||||
* @param int $id | ||||||
* @param string $label | ||||||
* @param bool $notified | ||||||
* @param \DateTimeInterface $created | ||||||
* @param string $comment | ||||||
* @param int $type | ||||||
* @return array | ||||||
*/ | ||||||
private function _prepareHistoryItemWithId( | ||||||
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. Please remove the underscore from the method name, it was an old practice from Magento 1, the new code shouldn't contain it
Suggested change
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. @ihor-sviziev I have updated this function name and addressed the other un-related files that creeped into this pull request. Shame on me for not following git best-practices... Sorry this got a bit messy. I think this is all straightened out now. |
||||||
int $id, | ||||||
string $label, | ||||||
bool $notified, | ||||||
\DateTimeInterface $created, | ||||||
string $comment = '', | ||||||
int $type = 0 | ||||||
): array { | ||||||
return [ | ||||||
'entity_id' => $id, | ||||||
'title' => $label, | ||||||
'notified' => $notified, | ||||||
'comment' => $comment, | ||||||
'created_at' => $created, | ||||||
'type' => $type | ||||||
]; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @inheritdoc | ||||||
*/ | ||||||
|
@@ -307,6 +364,28 @@ public static function sortHistoryByTimestamp($a, $b) | |||||
return $createdAtA->getTimestamp() <=> $createdAtB->getTimestamp(); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Comparison For Sorting History By Timestamp and entity_id | ||||||
* | ||||||
* @param array $a | ||||||
* @param array $b | ||||||
* @return int | ||||||
*/ | ||||||
private function sortHistory(array $a, array $b): int | ||||||
{ | ||||||
$result = $this->sortHistoryByTimestamp($a, $b); | ||||||
if (0 !== $result) { | ||||||
return $result; | ||||||
} | ||||||
|
||||||
$result = $a['type'] <=> $b['type']; | ||||||
if (0 !== $result) { | ||||||
return $result; | ||||||
} | ||||||
|
||||||
return $a['entity_id'] <=> $b['entity_id']; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Get order admin date | ||||||
* | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,6 +11,7 @@ | |||||||||||||||||||||||||||||||||||||||
use Magento\Framework\Translate\Inline\ParserInterface; | ||||||||||||||||||||||||||||||||||||||||
use Magento\Framework\Translate\InlineInterface; | ||||||||||||||||||||||||||||||||||||||||
use Magento\Framework\Session\Config\ConfigInterface; | ||||||||||||||||||||||||||||||||||||||||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||
* Plugin for putting messages to cookies | ||||||||||||||||||||||||||||||||||||||||
|
@@ -59,6 +60,11 @@ class MessagePlugin | |||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||
protected $sessionConfig; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||
* @var ScopeConfigInterface | ||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||
protected $scopeConfig; | ||||||||||||||||||||||||||||||||||||||||
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. Please make it private
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||
* @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager | ||||||||||||||||||||||||||||||||||||||||
* @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory | ||||||||||||||||||||||||||||||||||||||||
|
@@ -67,6 +73,7 @@ class MessagePlugin | |||||||||||||||||||||||||||||||||||||||
* @param \Magento\Framework\Serialize\Serializer\Json $serializer | ||||||||||||||||||||||||||||||||||||||||
* @param InlineInterface $inlineTranslate | ||||||||||||||||||||||||||||||||||||||||
* @param ConfigInterface $sessionConfig | ||||||||||||||||||||||||||||||||||||||||
* @param ScopeConfigInterface $scopeConfig | ||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||
public function __construct( | ||||||||||||||||||||||||||||||||||||||||
\Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, | ||||||||||||||||||||||||||||||||||||||||
|
@@ -75,7 +82,8 @@ public function __construct( | |||||||||||||||||||||||||||||||||||||||
\Magento\Framework\View\Element\Message\InterpretationStrategyInterface $interpretationStrategy, | ||||||||||||||||||||||||||||||||||||||||
\Magento\Framework\Serialize\Serializer\Json $serializer, | ||||||||||||||||||||||||||||||||||||||||
InlineInterface $inlineTranslate, | ||||||||||||||||||||||||||||||||||||||||
ConfigInterface $sessionConfig | ||||||||||||||||||||||||||||||||||||||||
ConfigInterface $sessionConfig, | ||||||||||||||||||||||||||||||||||||||||
ScopeConfigInterface $scopeConfig | ||||||||||||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||||||||||||
$this->cookieManager = $cookieManager; | ||||||||||||||||||||||||||||||||||||||||
$this->cookieMetadataFactory = $cookieMetadataFactory; | ||||||||||||||||||||||||||||||||||||||||
|
@@ -84,6 +92,7 @@ public function __construct( | |||||||||||||||||||||||||||||||||||||||
$this->interpretationStrategy = $interpretationStrategy; | ||||||||||||||||||||||||||||||||||||||||
$this->inlineTranslate = $inlineTranslate; | ||||||||||||||||||||||||||||||||||||||||
$this->sessionConfig = $sessionConfig; | ||||||||||||||||||||||||||||||||||||||||
$this->scopeConfig = $scopeConfig; | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||
|
@@ -171,11 +180,36 @@ private function setCookie(array $messages) | |||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
$publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata(); | ||||||||||||||||||||||||||||||||||||||||
$publicCookieMetadata->setDurationOneYear(); | ||||||||||||||||||||||||||||||||||||||||
$publicCookieMetadata->setPath($this->sessionConfig->getCookiePath()); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
if( $configLifetime = $this->scopeConfig->getValue( | ||||||||||||||||||||||||||||||||||||||||
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. I don't think this change is related to the issue you're trying to fix. Could you please revert it? |
||||||||||||||||||||||||||||||||||||||||
'web/cookie/cookie_lifetime', | ||||||||||||||||||||||||||||||||||||||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE | ||||||||||||||||||||||||||||||||||||||||
) ) { | ||||||||||||||||||||||||||||||||||||||||
$publicCookieMetadata->setDuration($configLifetime); | ||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||
$publicCookieMetadata->setDurationOneYear(); | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
if( $configPath = $this->scopeConfig->getValue( | ||||||||||||||||||||||||||||||||||||||||
'web/cookie/cookie_path', | ||||||||||||||||||||||||||||||||||||||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE | ||||||||||||||||||||||||||||||||||||||||
) ) { | ||||||||||||||||||||||||||||||||||||||||
$publicCookieMetadata->setPath($configPath); | ||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||
$publicCookieMetadata->setPath($this->sessionConfig->getCookiePath()); | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
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. I don't think this change is related to the issue you're trying to fix. Could you please revert it?
Suggested change
PS: you can create a new branch and add them to it, so they won't affect this PR. |
||||||||||||||||||||||||||||||||||||||||
$publicCookieMetadata->setHttpOnly(false); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
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. and this
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
$publicCookieMetadata->setSameSite('Strict'); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
if( $configDomain = $this->scopeConfig->getValue( | ||||||||||||||||||||||||||||||||||||||||
'web/cookie/cookie_domain', | ||||||||||||||||||||||||||||||||||||||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE | ||||||||||||||||||||||||||||||||||||||||
) ) { | ||||||||||||||||||||||||||||||||||||||||
$publicCookieMetadata->setDomain($configDomain); | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
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. And this
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
$this->cookieManager->setPublicCookie( | ||||||||||||||||||||||||||||||||||||||||
self::MESSAGES_COOKIES_NAME, | ||||||||||||||||||||||||||||||||||||||||
$this->serializer->serialize($messages), | ||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ | |||||||
* See COPYING.txt for license details. | ||||||||
*/ | ||||||||
?> | ||||||||
<?php $helperConfig = $this->helper('Magento\Theme\Helper\Data'); ?> | ||||||||
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. And this
Suggested change
|
||||||||
<div data-bind="scope: 'messages'"> | ||||||||
<!-- ko if: cookieMessages && cookieMessages.length > 0 --> | ||||||||
<div aria-atomic="true" role="alert" data-bind="foreach: { data: cookieMessages, as: 'message' }" class="messages"> | ||||||||
|
@@ -35,7 +36,8 @@ | |||||||
"Magento_Ui/js/core/app": { | ||||||||
"components": { | ||||||||
"messages": { | ||||||||
"component": "Magento_Theme/js/view/messages" | ||||||||
"component": "Magento_Theme/js/view/messages", | ||||||||
"cookieDomain": "<?= $helperConfig->getConfig( 'web/cookie/cookie_domain' ) ?>" | ||||||||
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. And this
Suggested change
|
||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -41,7 +41,7 @@ define([ | |||||
|
||||||
$.mage.cookies.set('mage-messages', '', { | ||||||
samesite: 'strict', | ||||||
domain: '' | ||||||
domain: this.cookieDomain | ||||||
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. And this
Suggested change
|
||||||
}); | ||||||
}, | ||||||
|
||||||
|
Uh oh!
There was an error while loading. Please reload this page.