Skip to content

Commit c51817f

Browse files
#39905 Product Removed on Mobile Still Appears in Web's Mini Compare Section Until Re-login
Refactor CompareCookieManager to use readonly properties Replaced manually assigned properties with readonly properties in the constructor to simplify initialization and improve immutability. Updated exception handling to use the imported Exception class instead of a fully qualified name.
1 parent 402ce4f commit c51817f

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

app/code/Magento/CompareListGraphQl/Model/Service/CompareCookieManager.php

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\CompareListGraphQl\Model\Service;
99

10+
use Exception;
1011
use Magento\Framework\Stdlib\CookieManagerInterface;
1112
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
1213
use Magento\Framework\Exception\InputException;
@@ -36,34 +37,16 @@ class CompareCookieManager
3637
*/
3738
public const COOKIE_LIFETIME = 86400;
3839

39-
/**
40-
* @var CookieManagerInterface
41-
*/
42-
private CookieManagerInterface $cookieManager;
43-
44-
/**
45-
* @var CookieMetadataFactory
46-
*/
47-
private CookieMetadataFactory $cookieMetadataFactory;
48-
49-
/**
50-
* @var LoggerInterface
51-
*/
52-
private LoggerInterface $logger;
53-
5440
/**
5541
* @param CookieManagerInterface $cookieManager
5642
* @param CookieMetadataFactory $cookieMetadataFactory
5743
* @param LoggerInterface $logger
5844
*/
5945
public function __construct(
60-
CookieManagerInterface $cookieManager,
61-
CookieMetadataFactory $cookieMetadataFactory,
62-
LoggerInterface $logger
46+
private readonly CookieManagerInterface $cookieManager,
47+
private readonly CookieMetadataFactory $cookieMetadataFactory,
48+
private readonly LoggerInterface $logger
6349
) {
64-
$this->cookieManager = $cookieManager;
65-
$this->cookieMetadataFactory = $cookieMetadataFactory;
66-
$this->logger = $logger;
6750
}
6851

6952
/**
@@ -76,7 +59,7 @@ public function invalidate(): void
7659
try {
7760
$cookieValue = json_encode(['compare-products' => time()]);
7861
$this->setCookie($cookieValue);
79-
} catch (\Exception $e) {
62+
} catch (Exception $e) {
8063
$this->logger->error('Error invalidating compare products cookie: ' . $e->getMessage());
8164
}
8265
}

0 commit comments

Comments
 (0)