I have a html file not a .phtml file, i want to check custom is log in or not in html file, how can i do this?
Asked
Active
Viewed 70 times
1
-
An html file is not the place to check whether the customer is logged in or not – vitoriodachef Jun 28 '19 at 08:07
-
I want to hide one button in checkout page but the button code are store in html page, how can i hide that button if customer is not login @vitoriodachef – Vardhman Kamani Jun 28 '19 at 08:41
-
Refer the link for same https://magento.stackexchange.com/questions/203951/magento2-check-if-customer-is-logged-in-or-not-in-knockout-template?rq=1 – Kirti Nariya Jun 28 '19 at 08:50
1 Answers
0
You have to create a function in knockout and call this function to html file.
You need to pass dependency of customer object, 'Magento_Customer/js/model/customer'
Your JS should be like this.
define(
[
'ko',
'jquery',
'Magento_Customer/js/model/customer',
'mage/translate'
],
function (ko,jquery, customer,$t) {
'use strict';
return Component.extend({
isCustomerLoggedIn: customer.isLoggedIn, /*return boolean true/false */
initialize: function() {
this._super();
/* check using below method */
var isLoggedIn = this.isCustomerLoggedIn();
}
});
}
And in your phtml file call function data-bind="attr: { attr: isCustomerLoggedIn()}"
Take reference from magento2 check if customer is logged in or not in knockout template
I hope it helps!
Chirag Patel
- 6,126
- 2
- 23
- 65
-
-
I have just shared logic
customer.isLoggedInusing this you can get customer logged in or not, you have to create function. – Chirag Patel Jun 28 '19 at 11:21 -