cancel
Showing results for 
Search instead for 
Did you mean: 

how to put login conditon to html button

SOLVED

how to put login conditon to html button

Hi guys,

                i just want to know how to put login conditon to html button .

can anyone help me on that ?

here is my code :

<?php foreach ($_review->getRatingVotes() as $_vote):?>
<div class="helpLinks">
<button class="reviewId"  value="<?php echo $key ?>"> Helpful </button>
</div>
<?php endforeach; ?>

1 ACCEPTED SOLUTION

Accepted Solutions

Re: how to put login conditon to html button

@bharath553  what condition as i don't understend it from your question and you can place the login url "/customer/account/login" where your condition false.

 

View solution in original post

6 REPLIES 6

Re: how to put login conditon to html button

@bharath553  can you please be specific what you are looking for and for login condition you can use 

 

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->create('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) : ?>
<span class="header_account_link_list logout">
<a class= "header_account_link" href="<?php echo $this->getUrl("customer/account/logout");?>"><?php echo __('Logout')?></a>
</span>
<?php else: ?>
<span class="header_account_link_list login">
<a class= "header_account_link" href="<?php echo $this->getUrl("customer/account/login");?>"><?php echo __('Sign in')?></a>
</span>
<?php endif;?>

If this help you accept this as solution and give kudos.

Re: how to put login conditon to html button

HI,

Re: how to put login conditon to html button

Hi, thanks for you reply but, i just need redirection to login page. if the condition fail.

how can i do that ?

Re: how to put login conditon to html button

@bharath553  what condition as i don't understend it from your question and you can place the login url "/customer/account/login" where your condition false.

 

Re: how to put login conditon to html button

i wrote like below. But , my question is i just want to redirect to same page after login. can you help me on this ?

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->create('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) { ?>
<div class="helpLinks">
<ul class="header links">
<li>

<div class="countersection" id="<?php echo $key; ?>">

<a href="" class="reviewId" dbcount="<?php echo $dbcount ?>" value="<?php echo $key ?>"> Helpful </a>
<span id="finalresult" > </span>
</div>
</li>

</ul>
</div>
<?php }else {?>
<div class="helpLinks">
<ul class="header links">
<li>
<a href="<?php echo $this->getUrl("customer/account/login");?>">Helpful</a>
</li>

</ul>
</div>
<?php } ?>

Re: how to put login conditon to html button

@bharath553 

you can check this link

http://www.webspeaks.in/2016/09/magento2-redirect-same-page-customer-login.html

OR

1. Go to Admin -> Stores -> Settings -> Configuration -> Customers -> Customer Configuration
2. Now in the Login Options section change the Redirect Customer to Account Dashboard after Logging in settings to ‘No’
3. Clear the cache
if this help you accept this as solution and give kudos.