-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Get all session data from local storage
- Loading branch information
1 parent
b2794b8
commit 01498e9
Showing
4 changed files
with
32 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
<?php | ||
/** | ||
* @var $block \Magento\Framework\View\Element\Template | ||
* @var $viewModel \Emico\RobinHq\ViewModel\LoggedInCustomer | ||
*/ | ||
|
||
$viewModel = $block->getViewModel(); | ||
if (!$viewModel->shouldRender()) { | ||
return ''; | ||
} | ||
?> | ||
<script type="text/javascript"> | ||
if (typeof __robin !== 'undefined') { | ||
if (typeof __robin !== 'undefined' && isLoggedIn()) { | ||
var customer = getCustomer(); | ||
var robin_settings = { | ||
callback: function (event, data) { | ||
|
@@ -31,22 +25,39 @@ if (!$viewModel->shouldRender()) { | |
} | ||
|
||
/** | ||
* Get the customer from the local storage, because the PHP customer session is depersonalized on cached pages | ||
* @returns {Object} | ||
* Function to check if customer is logged in | ||
* @returns {boolean} | ||
*/ | ||
function getCustomer() | ||
{ | ||
if (localStorage.getItem('mage-cache-storage') != null) { | ||
var mageCacheStorage = JSON.parse(localStorage.getItem('mage-cache-storage')); | ||
function isLoggedIn() { | ||
var mageCacheStorage = getMageCacheStorage(); | ||
|
||
if (typeof mageCacheStorage.customer !== 'undefined') { | ||
return mageCacheStorage.customer; | ||
} | ||
return mageCacheStorage != null && typeof mageCacheStorage.customer !== 'undefined'; | ||
} | ||
|
||
/** | ||
* Get the customer from the local storage, because the PHP customer session is depersonalized on cached pages | ||
* @returns {Object} | ||
*/ | ||
function getCustomer() { | ||
var mageCacheStorage = getMageCacheStorage(); | ||
if (mageCacheStorage != null && typeof mageCacheStorage.customer !== 'undefined') { | ||
return mageCacheStorage.customer; | ||
} | ||
|
||
return { | ||
fullName: 'Unknown', | ||
fullname: 'Unknown', | ||
email: '[email protected]' | ||
}; | ||
} | ||
|
||
/** | ||
* @returns {Object|null} | ||
*/ | ||
function getMageCacheStorage() | ||
{ | ||
if (localStorage.getItem('mage-cache-storage') != null) { | ||
return JSON.parse(localStorage.getItem('mage-cache-storage')); | ||
} | ||
return null; | ||
} | ||
</script> |