Post by RichMo » Tue Jul 10, 2012 6:02 pm

Hi,

My shop is installed as "example.com/shop", and I would like to be able to use the opencart login to allow access to other parts of my site. i.e. pages that are not within the /shop/ directory.

Is this possible?

For example, in a page such as example.com/example.php...

if (user is logged on) {
echo "Welcome Username";
} else {
echo "Welcome Guest, please log in";
}

New member

Posts

Joined
Tue Jul 10, 2012 5:54 pm

Post by mcamca » Tue Jul 10, 2012 6:28 pm

Try this:

Code: Select all

      <?php if (!$logged) { ?>
      You must be logged in to view this page! Please Register or Login!
      <?php } else { ?>
      <a href="The link you want!">View Page!</a>
     <?php } ?>
If you get an undefined error let us know!
Modify text to what you require!
Last edited by mcamca on Tue Jul 10, 2012 6:37 pm, edited 1 time in total.

Active Member

Posts

Joined
Fri Aug 06, 2010 5:57 pm

Post by RichMo » Tue Jul 10, 2012 6:36 pm

It just shows as not logged in.

I assume I will need to include some of the opencart core files first so that it has some contents for the $logged variable

New member

Posts

Joined
Tue Jul 10, 2012 5:54 pm

Post by mcamca » Tue Jul 10, 2012 6:39 pm

Try it first and then let me know whether you get an undefined error! (You may well not need to alter anything!)
If it shows as not logged in then login yourself and see if it shows the same!

Active Member

Posts

Joined
Fri Aug 06, 2010 5:57 pm

Post by mcamca » Tue Jul 10, 2012 7:32 pm

If you get an undefined index "logged" then enter the following into the controller for the page that you have entered the above code into (I presume that your using an information page???):

Code: Select all

$this->load->model('account/customer');	
$this->data['logged'] = $this->customer->isLogged();
If you need to show the customers name etc then you need additional code in this controller.php plus addition to the model for this controller!
LET ME KNOW WHAT HAPPENS!
Have other work to do know so I'm logging off now!

Active Member

Posts

Joined
Fri Aug 06, 2010 5:57 pm

Post by RichMo » Tue Jul 10, 2012 11:16 pm

It does not say undefined because $logged is just an empty variable.

The page being loaded is OUTSIDE of the opencart directory, and it is not a file generated by opencart. the entire contents of the php file are....

Code: Select all

<?php if (!$logged) { ?>
      You must be logged in to view this page! Please Register or Login!
      <?php } else { ?>
      <a href="The link you want!">View Page!</a>
<?php } ?>
So it is always going to tell me not logged in unless before this, I have some references to the opencart system files. I presume there will be some core includes, then perhaps some function call to get the database/cookie info. I'm just not sure where to start.

New member

Posts

Joined
Tue Jul 10, 2012 5:54 pm

Post by mcamca » Tue Jul 10, 2012 11:34 pm

Sorry, I thought that you were operating on Opencart and that you wanted to stop access to a link that was independent of Opencart unless the user was logged in!
You can certainly do this when you have Opencart loaded! Have several sites which do this without operating the shopping cart portion of Opencart!
From the point of view of a standard site, and selecting just certain core files from Opencart then sorry but cannot help any further!

Active Member

Posts

Joined
Fri Aug 06, 2010 5:57 pm

Post by RichMo » Wed Jul 11, 2012 7:45 pm

Ok, well I have looked through the opencart files and have now added a couple of include files.

Code: Select all

<?
include_once ("shop/config.php");
include_once ("shop/system/startup.php");
if (!$logged) {
	echo "You must be logged in to view this page! Please Register or Login!";
} else {
	echo "<a href=\"The link you want!\">View Page!</a>";
}
?>
This gives me an undefined error saying that "logged" is undefined. If I add the other code you mentioned...

Code: Select all

<?
include_once ("shop/config.php");
include_once ("shop/system/startup.php");

$this->load->model('account/customer');   
$this->data['logged'] = $this->customer->isLogged();

if (!$logged) {
	echo "You must be logged in to view this page! Please Register or Login!";
} else {
	echo "<a href=\"The link you want!\">View Page!</a>";
}
?>
I get another error...
"Fatal error: Using $this when not in object context..."

New member

Posts

Joined
Tue Jul 10, 2012 5:54 pm

Post by mcamca » Wed Jul 11, 2012 8:51 pm

The code I gave only works if used within the Opencart structure which is pretty complex. Various things are defined by many different files and hence to operate correctly all files must be loaded!
You probably have two options:
1. Load Opencart to your server (You'll need sql) and operate your site by nullifying content/links etc that you dont want to use!
Or
2. Forget Opencart and use javascript and cookies to achieve what you want; but you are in the wrong forum to get answers on how to do this! Opencart forums usually deal with questions re. Opencart!

Active Member

Posts

Joined
Fri Aug 06, 2010 5:57 pm

Post by RichMo » Sun Jul 15, 2012 1:56 am

Opencart forums usually deal with questions re. Opencart!
It is specifically the opencart code I am using, and want help with. (it is installed in example.com/shop). I appreciate that you're trying to help, but please stop guessing / not reading my question, as I need help from someone who actually understands the "pretty complex" structure of the opencart system. Perhaps I should post under a different category.

New member

Posts

Joined
Tue Jul 10, 2012 5:54 pm

Post by mcamca » Sun Jul 15, 2012 6:37 am

I have had to guess as this is the first time that you have mentioned that you are operating on the Opencart system.
You also have not mentioned the Opencart version you are using!
You apparently have no understanding of the way in which opencart works! To explain roughly:
The code that checks whether the customer is logged in can be on the template page eg contact.tpl
The items called for eg. $logged has to be defined in the controller for that page eg. contact.php
This has to call for a check via a database query which is called for in contact.php from customers.php located in model.
The text eg. $text_firstname is defined in contact.php and called from another contact.php located in languages.
I assure you I do know what I am doing as I have many different pages on many different versions of Opencart which does exactly what you are asking for!
But as far as I'm concerned your gonna have to work it out for yourself; as I did!
Is anyone else willing to show him how to do it?

Active Member

Posts

Joined
Fri Aug 06, 2010 5:57 pm

Post by mcamca » Sun Jul 15, 2012 7:49 pm

I'll give you a clue!
Checking for whether a user is logged in or not is used on every page that you see on your screen when viewing any Opencart site!
If you are capable enough then you should be able to extract the code required to check whether a user is logged in anywhere on your Opencart site!
Enjoy!

Active Member

Posts

Joined
Fri Aug 06, 2010 5:57 pm

Post by RichMo » Sun Jul 15, 2012 8:24 pm

Thanks, I thought that as this is an opencart forum, and I am talking about my shop, it would be assumed that I was talking about an opencart shop. Anyways...

In addition to the code in the previous posts, I assume that I need to load some of the stuff in the "shop/index.php" file. I'm just not sure which bits I need, or how to load it correctly. If I copy the contents of that file into my test file I still get an undefined "logged" error. (I deleted the part of the code that actually loads the page, otherwise the templates get loaded)
I removed this part...

Code: Select all

// Install 
if (!defined('DIR_APPLICATION')) {
	header('Location: install/index.php');
	exit;
}
I think I must need to do something like this...

Code: Select all

$session->load->model('account/customer');   
$session->data['logged'] = $this->customer->isLogged();
...because I can not use "$this". I've tried $session, $controller, and $registry, but I get an error like this...

"Undefined property: Session::$load" and "Call to a member function model() on a non-object"

New member

Posts

Joined
Tue Jul 10, 2012 5:54 pm

Post by mcamca » Sun Jul 15, 2012 8:33 pm

OK as long as there are no more insults I'll try and help!
1 First of all which version number of Opencart are you using?
2. From where within Opencart are you trying to check as to whether the user is logged in? (You cannot do this from the "shop/index.php" file.) If you dont understand this question then say!

Active Member

Posts

Joined
Fri Aug 06, 2010 5:57 pm

Post by RichMo » Sun Jul 15, 2012 8:52 pm

This is the whole point. It is not within opencart (version 1.5.3.1).

Shop is here..
"example.com/shop/index.php"

My file is here..
"example.com/test.php"

test.php will not be affected by, and will not affect the opencart system unless some code is added to test.php to specifically do that.

I've been using Cubecart for a couple of years, and I really regret that I actually paid money for it. It is really not good at all. I made a stupid assumption that a paid one must be better than the free ones. Doh! I have however been able to use its authentication feature outside the install folder. I must be able to do this with opencart if I am to replace my current Cubecart shop with it.

New member

Posts

Joined
Tue Jul 10, 2012 5:54 pm

Post by mcamca » Sun Jul 15, 2012 9:21 pm

How many products do you sell?

Active Member

Posts

Joined
Fri Aug 06, 2010 5:57 pm

Post by RichMo » Sun Jul 15, 2012 9:23 pm

about 150 currently

New member

Posts

Joined
Tue Jul 10, 2012 5:54 pm

Post by mcamca » Sun Jul 15, 2012 9:40 pm

Pretty sure you wont be able to do what you want!
You'd be better installing/transferring all of your products with pics individually into Opencart v1.5.3.1 via opencart admin. Sounds a lot of work but I loaded 250 products in this way in 2 days. You can then use the complete functionality of Opencart.
Dont think you'll do this with an SQL file as the table fields are specific to Opencart.
Load Opencart to:
http://www.example.com/new_shop/
after creating a new database.
Fill with all of your products, make or buy a template to match what you need for look, test for correct functionality and if working OK then rename "new_shop" to "shop"
such that the opencart site is now at:
http://www.example.com/shop/
(You'll probably have to change config.php also!)
PS. You probably already know but SQL and php5 are required on your server!

Active Member

Posts

Joined
Fri Aug 06, 2010 5:57 pm

Post by RichMo » Sun Jul 15, 2012 9:45 pm

I already transferred my products, customers, and invoices using a script I bought online.
http://stsoft.eu/products/cart-to-cart- ... te-support
It wasn't perfect but made the process very easy.

New member

Posts

Joined
Tue Jul 10, 2012 5:54 pm

Post by mcamca » Sun Jul 15, 2012 9:48 pm

That links handy to have!
When you've got everything in your site complete on Opencart, then ask the question re: checking for logged in again!

Active Member

Posts

Joined
Fri Aug 06, 2010 5:57 pm
Who is online

Users browsing this forum: No registered users and 5 guests