1313use Magento \Customer \Model \Config \Share ;
1414use Magento \Customer \Model \ResourceModel \Customer as ResourceCustomer ;
1515use Magento \Framework \App \ObjectManager ;
16+ use Magento \Framework \Exception \NoSuchEntityException ;
1617use Magento \Framework \Session \Generic ;
1718
1819/**
@@ -107,6 +108,11 @@ class Session extends \Magento\Framework\Session\SessionManager
107108 */
108109 private $ accountConfirmation ;
109110
111+ /**
112+ * @var CustomerRegistry
113+ */
114+ private $ customerRegistry ;
115+
110116 /**
111117 * Session constructor.
112118 *
@@ -132,6 +138,7 @@ class Session extends \Magento\Framework\Session\SessionManager
132138 * @param GroupManagementInterface $groupManagement
133139 * @param \Magento\Framework\App\Response\Http $response
134140 * @param AccountConfirmation $accountConfirmation
141+ * @param CustomerRegistry $customerRegistry
135142 * @throws \Magento\Framework\Exception\SessionException
136143 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
137144 */
@@ -157,7 +164,8 @@ public function __construct(
157164 CustomerRepositoryInterface $ customerRepository ,
158165 GroupManagementInterface $ groupManagement ,
159166 \Magento \Framework \App \Response \Http $ response ,
160- AccountConfirmation $ accountConfirmation = null
167+ AccountConfirmation $ accountConfirmation = null ,
168+ CustomerRegistry $ customerRegistry = null
161169 ) {
162170 $ this ->_coreUrl = $ coreUrl ;
163171 $ this ->_customerUrl = $ customerUrl ;
@@ -173,6 +181,8 @@ public function __construct(
173181 $ this ->response = $ response ;
174182 $ this ->accountConfirmation = $ accountConfirmation ?: ObjectManager::getInstance ()
175183 ->get (AccountConfirmation::class);
184+ $ this ->customerRegistry = $ customerRegistry ?: ObjectManager::getInstance ()
185+ ->get (CustomerRegistry::class);
176186 parent ::__construct (
177187 $ request ,
178188 $ sidResolver ,
@@ -299,14 +309,15 @@ public function setCustomer(Customer $customerModel)
299309 *
300310 * @return Customer
301311 * use getCustomerId() instead
312+ * @throws NoSuchEntityException
302313 */
303314 public function getCustomer ()
304315 {
305316 if ($ this ->_customerModel === null ) {
306317 $ this ->_customerModel = $ this ->_customerFactory ->create ();
307318
308319 if ($ this ->getCustomerId ()) {
309- $ this ->_customerResource -> load ( $ this ->_customerModel , $ this ->getCustomerId ());
320+ $ this ->_customerModel = $ this ->customerRegistry -> retrieve ( $ this ->getCustomerId ());
310321 }
311322 }
312323
@@ -385,8 +396,8 @@ public function getCustomerGroupId()
385396 if ($ this ->storage ->getData ('customer_group_id ' )) {
386397 return $ this ->storage ->getData ('customer_group_id ' );
387398 }
388- if ($ this ->getCustomerData ()) {
389- $ customerGroupId = $ this ->getCustomerData ()->getGroupId ();
399+ if ($ this ->getCustomer ()) {
400+ $ customerGroupId = $ this ->getCustomer ()->getGroupId ();
390401 $ this ->setCustomerGroupId ($ customerGroupId );
391402 return $ customerGroupId ;
392403 }
@@ -431,7 +442,7 @@ public function checkCustomerId($customerId)
431442 }
432443
433444 try {
434- $ this ->customerRepository -> getById ($ customerId );
445+ $ this ->customerRegistry -> retrieve ($ customerId );
435446 $ this ->_isCustomerIdChecked = $ customerId ;
436447 return true ;
437448 } catch (\Exception $ e ) {
0 commit comments