Jump to content

How to Hide shop or Page when not logged in ver 1.5.4


Never_give_up

Recommended Posts

Hello everyone, I would like to hide the store or the index page until the customer logs in. I am using 1.5.4 with mulistore on and two separate themes for 2 stores (the wholesale store is within the default retail store), I just need the wholesale shop index page or full wholesale store to be hidden until sign in.
 
I found this code to add to index.tpl,  but it's not working… 
 
{if $logged}
/* Your private page to show when the user is logged in */
<div>Welcome</div>
    {else}
/* You elements to show message when the user is not logged in */ 
<div>You must sign-in to view this page</div>
    {if} 

Does anyone know what code I need to update or change to do this? I am not looking for a module to do it. I prefer to just change or add code. Thank you so much!

Link to comment
Share on other sites

I was able to figure out how to get this to work as a private store with login page before entering store. Here's what to do....
 
The code above does work I just did'nt know where to place it to hide and lock up the whole store plus it had a missing slant in the <if> instead of </if> at the end. First I must say any private store using "only" CSS to hide it it and lock it up is not a secure way to do it. That being said from what I researched I believe this simple code "if logged" is more secure with ssl other then changing core Php code to do it. 
 
What finally worked well was to lock-up and hide the entire wholesale store and make it a private store until the customer signs-in. Every .tpl page will be locked up and private except the header.tpl will only be half private until login and the other half will have a login box which will only show up if the customer is not logged in. Doing it this way you can customize the whole login page to what ever you want and not have it affect the original store register/login page. You are basically going to add your own html or css code for the layout and add a sign-in/login box in this area that only shows before logged-in.
 
First step backup all the .tpl files from the theme folder to your computer using FTP. 2nd step lock up and hide all .tpl pages by adding the below code at the top of each page before ALL original code.  Don't add it to the header.tpl yet.
 

 {if $logged}
/* All code below this will be locked-up and hidden if not logged-in */

 
At the very bottom of each .tpl page add this (except the header.tpl):

{else}
 {/if} 

 
In header.tpl add  {if $logged} right after </head>

 {if $logged}
/* All code below this will be locked-up and hidden if not logged-in */

 
Now you're going to sandwich some code on how you what the page to look with a sign-in box. Basically I copied some sign-in code from authentication.tpl to the header.tpl
 
At the very bottom of header.tpl add:

{else}
/* All code sandwiched between the {else} and the {/if} will show up when not logged-in. This is where to put your custom html and sign-in code */
 
{/if} 

 
 
in-between {else} and the {/if} I added this code:
 

<div style="background: #000000 url(https://yourdomainname.com/themes/yourtheme/css/wloginbackground.jpg) no-repeat center top;height: 100%; width: 100%;
				-webkit-background-size: cover;
				-moz-background-size: cover;
				background-size: cover;
">


<div><strong><span background="/wlogin.jpg"style="color: #ff0000; font-size: 16px;"></span></strong></div>

    
    
    
    
   {if !isset($dlv_all_fields)}
		{$dlv_all_fields.0 = 'company'}
		{$dlv_all_fields.1 = 'firstname'}
		{$dlv_all_fields.2 = 'lastname'}
		{$dlv_all_fields.3 = 'address1'}
		{$dlv_all_fields.4 = 'address2'}
		{$dlv_all_fields.5 = 'postcode'}
		{$dlv_all_fields.6 = 'city'}
		{$dlv_all_fields.7 = 'country'}
		{$dlv_all_fields.8 = 'state'}
{/if}

{capture name=path}{l s='Login'}{/capture}
{include file="$tpl_dir./breadcrumb.tpl"}

<script type="text/javascript">
// <![CDATA[
idSelectedCountry = {if isset($smarty.post.id_state)}{$smarty.post.id_state|intval}{else}false{/if};
countries = new Array();
countriesNeedIDNumber = new Array();
countriesNeedZipCode = new Array();
{if isset($countries)}
	{foreach from=$countries item='country'}
		{if isset($country.states) && $country.contains_states}
			countries[{$country.id_country|intval}] = new Array();
			{foreach from=$country.states item='state' name='states'}
				countries[{$country.id_country|intval}].push({ldelim}'id' : '{$state.id_state}', 'name' : '{$state.name|escape:'htmlall':'UTF-8'}'{rdelim});
			{/foreach}
		{/if}
		{if $country.need_identification_number}
			countriesNeedIDNumber.push({$country.id_country|intval});
		{/if}
		{if isset($country.need_zip_code)}
			countriesNeedZipCode[{$country.id_country|intval}] = {$country.need_zip_code};
		{/if}
	{/foreach}
{/if}
$(function(){ldelim}
	$('.id_state option[value={if isset($smarty.post.id_state)}{$smarty.post.id_state}{else}{if isset($address)}{$address->id_state|escape:'htmlall':'UTF-8'}{/if}{/if}]').attr('selected', 'selected');
{rdelim});
//]]>
{if $vat_management}
	{literal}
	$(document).ready(function() {
		$('#company').blur(function(){
			vat_number();
		});
		vat_number();
		function vat_number()
		{
			if ($('#company').val() != '')
				$('#vat_number').show();
			else
				$('#vat_number').hide();
		}
	});
	{/literal}
{/if}
</script>
<h1>{if !isset($email_create)}{l s=''}{/if}</h1>
{assign var='current_step' value='login'}
{include file="$tpl_dir./order-steps.tpl"}

{include file="$tpl_dir./errors.tpl"}
{assign var='stateExist' value=false}
{if !isset($email_create)}
		<form action="{$link->getPageLink('authentication.php', true)}" method="post" id="login_form" class="std">
		<fieldset>
			
			<div style="padding: 100px 0 0 250px;">
<img class="logo" src="/img/your-logo.png" height="55" width="200" alt="">

<div id="login-box">

<H2a>Login</H2a>
For register wholesale users only. If you're not registered please go to the <a href="https://yourdomain.com/wholesale-inquiries" style="color: #E80202">wholesale registration form</a>.
<br />
<br />
<div id="login-box-name" style="margin-top:20px;">Email:</div><div id="login-box-field" style="margin-top:20px;">
<input type="text" id="email" name="email" class="form-login" title="Username" value="{if isset($smarty.post.email)}{$smarty.post.email|escape:'htmlall':'UTF-8'|stripslashes}{/if}" size="30" maxlength="2048" /></div>
<div id="login-box-name">Password:</div>
<div id="login-box-field">
<input type="password" id="passwd" name="passwd" class="form-login" title="Password" value="{if isset($smarty.post.passwd)}{$smarty.post.passwd|escape:'htmlall':'UTF-8'|stripslashes}{/if}" size="30" maxlength="2048" /></div>
<br />
<span class="login-box-options"><a href="https://your-retail-domain.com.com/contact-us" style="margin-left:30px;">Forgot password? please contact us</a></span>
<br />
<br />
<p class="submit">
				<input type="hidden" class="hidden" name="back" value="{$smarty.server.HTTP_REFERER}" />
				<input type="submit" id="SubmitLogin" name="SubmitLogin" class="button_large" value="{l s='Log in'}" />
			</p>
			<br />
<br />
			<span class="login-box-options"><a href="http://your-retail-domain.com" style=";">Back to Retail Store</a></span>

</div>
</div>
		</fieldset>
	</form>

{/if}
 
  </div>

 
Download these files:blue-login-box.zip

 

Ok one last thing you have to do…  Change the above code anywhere it states "yourdomain.com" or  "your-retail-domain.com" to your domain addresses.  The free sign in box I used was called "blue-login-box". You have to download the files above to get the sign in box looking good with css and images. I attached  them above. After you download the files copy the login-box.css to the css theme folder, also copy the images to the CSS folder. I don't know why but coping the images to the img folder did not show up no matter if I changed the address to  img folder. The images only showed up from the css folder, strange! I changed the Blue background sign-in box image to black. if you change the name of the background image be sure to change the name in the background link in login-box.css …. You can also play with the css color and layout to fit your style for the login page. 

 
One of the things I didn't get to work out yet was the "forgot your password" code, it was going in a loop so I must of missed some "forgot your password" code. For now I just put a link to the "contact us" form from the retail store. If the customer forgets the password that was set up for them they can just contact us.
 
How to make a wholesale registration form...
 
I have also made a wholesale registration form on the retail store so wholesale buyers can register for the wholesale site. I made it by duping all the contact form files to contact2 files including Contact2Controller.php and mail files  then replacing all code that states contact to cantact2 in those files, then so it shows up on the front end I added the page in Admin under Preferences>>SEO>>Add New >> select the new contact2 page. Now just edit contact2.tpl and add extra input fields to what you want.
 
in contact2.tpl replace everything below the {include file="$tpl_dir./errors.tpl"}  with this:
{include file="$tpl_dir./errors.tpl"}
	<form action="{$request_uri|escape:'htmlall':'UTF-8'}" method="post" class="std" enctype="multipart/form-data">
		<fieldset>
			<br><br>
			 			
			
	{*ADDED START*}		{if isset($customerThread.id_contact)}
                                <input type="hidden" name="id_contact" value="{$customerThread.id_contact}" />
                        {else}
                                <input type="hidden" name="id_contact" value="1" />
        {*ADDED END*}                {/if}
			
			<p><center>{l s='All information is sent encrypted and securely.'}</center></p>
			<p class="text">
				<label for="email">{l s='E-mail address'}</label>
				{if isset($customerThread.email)}
					<input type="text" id="email" name="from" value="{$customerThread.email}" readonly="readonly"/>
				{else}
					<input type="text" id="email" name="from" value="{$email}" style="width:280px;height:18px"/>
				{/if}
			</p>
			
			<p>
			<label for="contactperson">{l s='Contact Name'}</label>
			<input type="text" id="contactperson" name="contactperson" style="width:280px;height:18px"value="{if isset($contactperson)}{$contactperson|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
		</p>
		
		<p>
			<label for="phonenumber">{l s='Phone Number'}</label>
			<input type="text" id="phonenumber" name="phonenumber" style="width:280px;height:18px" value="{if isset($phonenumber)}{$phonenumber|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
		</p>


<p>
			<label for="companyname">{l s='Business Name'}</label>
			<input type="text" id="companyname" name="companyname" style="width:280px;height:18px"value="{if isset($companyname)}{$companyname|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
		</p>

		<p class="textarea">
			<label for="businessaddress">{l s='Business Address'}</label>
			 <textarea id="businessaddress" name="businessaddress" rows="15" cols="20" style="width:280px;height:80px">{if isset($businessaddress)}{$businessaddress|escape:'htmlall':'UTF-8'|stripslashes}{/if}</textarea>
		</p>
		
		
		<p>
			<label for="country">{l s='Country'}</label>
			<input type="text" id="country" name="country" style="width:280px;height:18px" value="{if isset($country)}{$country|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
		</p>
<p class="textarea">
			<label for="message">{l s='Message or questions'}</label>
			 <textarea id="message" name="message" rows="15" cols="20" style="width:280px;height:120px">{if isset($message)}{$message|escape:'htmlall':'UTF-8'|stripslashes}{/if}</textarea>
		</p>

		
		<p class="submit">
			<input type="submit" name="submitMessage" id="submitMessage" value="{l s='Send'}" class="button_large" onclick="$(this).hide();" />
		</p>
	</fieldset>
</form>
{/if}

Add a link to the page somewhere on your retail store according to what you specified in the add to SEO from Admin. Last thing to do is edit the contact2.html and contact2.txt mail files to match your input boxes from contact2.tpl page.
 
Mail contact2.html to match input boxes from contact2.tpl :
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Message from {shop_name}</title>
</head>
<body>
<table style="font-family: Verdana,sans-serif; font-size: 11px; color: #374953; width: 550px;">
<tbody>
<tr>
<td align="left"><a title="{shop_name}" href="{shop_url}"><img style="border: none;" src="{shop_logo}" width="221" height="60" alt="{shop_name}" /></a></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td style="background-color: {color}; color: #fff; font-size: 12px; font-weight: bold; padding: 0.5em 1em;" align="left">Message from a {shop_name} Wholesale Inquiry customer</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td align="left">Customer e-mail address: <a href="mailto:{email}"><strong>{email}</strong></a> <br /><br />
  <p><strong>Contact Name:</strong><br>
{contactperson}<br />
    {phonenumber}<br />
  <br />
    <strong>Business Name:<br>
    </strong>{companyname}<br />
  {businessaddress}<br>
  {country}</p>
  <p><strong>Message:</strong><br>
    {message}</p></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td style="font-size: 10px; border-top: 1px solid #D9DADE;" align="center"><a style="color: {color}; font-weight: bold; text-decoration: none;" href="{shop_url}">www.yoururl.com</a></td>
</tr>
</tbody>
</table>
</body>
</html>
 
These emails will not save to the database but you will get an email with all the information from the customer to follow through with the lead by calling them for more information to approve them for wholesale.  Then you can manually set them up in the wholesale site Admin with a password.
 
 
 I now have a working wholesale site that only registered users can enter. YAY!
Edited by Never_give_up (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...