Skip to content

Commit b165325

Browse files
committed
AC-5979: Rest API products-render-info return wrong final price for logged in customer
1 parent 64d3b9c commit b165325

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

app/code/Magento/Catalog/Plugin/Model/ProductRenderListPlugin.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class ProductRenderListPlugin
4949
*/
5050
private $logger;
5151

52+
/**
53+
* @var array Cache for customer group IDs
54+
*/
55+
private $customerGroupCache = [];
56+
5257
/**
5358
* @param UserContextInterface $userContext
5459
* @param CustomerRepositoryInterface $customerRepository
@@ -125,8 +130,11 @@ private function getCustomerGroupId(): ?int
125130
if ($userType === UserContextInterface::USER_TYPE_CUSTOMER) {
126131
$customerId = $this->userContext->getUserId();
127132
if ($customerId) {
128-
$customer = $this->customerRepository->getById($customerId);
129-
return (int)$customer->getGroupId();
133+
if (!isset($this->customerGroupCache[$customerId])) {
134+
$customer = $this->customerRepository->getById($customerId);
135+
$this->customerGroupCache[$customerId] = (int)$customer->getGroupId();
136+
}
137+
return $this->customerGroupCache[$customerId];
130138
}
131139
}
132140
// For guest users, return the not logged in group ID

app/code/Magento/Customer/Plugin/Model/Group/RetrieverPlugin.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class RetrieverPlugin
3535
*/
3636
private $appState;
3737

38+
/**
39+
* @var array Cache for customer group IDs
40+
*/
41+
private $customerGroupCache = [];
42+
3843
/**
3944
* @param UserContextInterface $userContext
4045
* @param CustomerRepositoryInterface $customerRepository
@@ -72,9 +77,11 @@ public function aroundGetCustomerGroupId(
7277
if ($userType === UserContextInterface::USER_TYPE_CUSTOMER) {
7378
$customerId = $this->userContext->getUserId();
7479
if ($customerId) {
75-
$customer = $this->customerRepository->getById($customerId);
76-
$customerGroupId = (int)$customer->getGroupId();
77-
return $customerGroupId;
80+
if (!isset($this->customerGroupCache[$customerId])) {
81+
$customer = $this->customerRepository->getById($customerId);
82+
$this->customerGroupCache[$customerId] = (int)$customer->getGroupId();
83+
}
84+
return $this->customerGroupCache[$customerId];
7885
}
7986
}
8087
return Group::NOT_LOGGED_IN_ID;

app/code/Magento/Customer/Plugin/Model/SessionPlugin.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class SessionPlugin
3535
*/
3636
private $appState;
3737

38+
/**
39+
* @var array Cache for customer group IDs
40+
*/
41+
private $customerGroupCache = [];
42+
3843
/**
3944
* @param UserContextInterface $userContext
4045
* @param CustomerRepositoryInterface $customerRepository
@@ -71,9 +76,11 @@ public function aroundGetCustomerGroupId(
7176
if ($userType === UserContextInterface::USER_TYPE_CUSTOMER) {
7277
$customerId = $this->userContext->getUserId();
7378
if ($customerId) {
74-
$customer = $this->customerRepository->getById($customerId);
75-
$customerGroupId = (int)$customer->getGroupId();
76-
return $customerGroupId;
79+
if (!isset($this->customerGroupCache[$customerId])) {
80+
$customer = $this->customerRepository->getById($customerId);
81+
$this->customerGroupCache[$customerId] = (int)$customer->getGroupId();
82+
}
83+
return $this->customerGroupCache[$customerId];
7784
}
7885
}
7986
return Group::NOT_LOGGED_IN_ID;

0 commit comments

Comments
 (0)