Page 1 of 2

Multi-Store Unique Customers

Posted: Wed Mar 09, 2011 1:08 pm
by cable
Hi:

Helping a friend with their opencart setup. Tried to search for this topic, but didn't come across this.

Is it possible to setup a multi-store where a customer from one cannot log into the other store?
Meaning the following:

1. User creates an account on Store 1
2. Goes to Store 2 and the same account credentials are not valid

From what it seems and currently based on my test, the user can go to Store 2 and login using the same credentials

Thanks. Any help is appreciated.

Re: Multi-Store Unique Customers

Posted: Wed Mar 09, 2011 6:38 pm
by mystifier
This is not possible with the standard system. You would have to implement a customer_to_store table linking customers to a store_id.

I don't know of anyone that offers this as an extension.

Re: Multi-Store Unique Customers

Posted: Wed Mar 09, 2011 9:29 pm
by fido-x
mystifier wrote:This is not possible with the standard system.
True.
You would have to implement a customer_to_store table linking customers to a store_id...
Ah, no. The store_id is stored in the customer table already.

Restricting customers to the store at which they registered their account hasn't been implemented. Modifications need to be made to "system/library/customer.php" to enable it.

Re: Multi-Store Unique Customers

Posted: Wed Mar 09, 2011 9:46 pm
by mystifier
So it is! It looks like some work was started but not completed.

Store_id is always set to default '0' but if you set it to the current store_id in catalog/controller/account/create.php, you are half way there.

Re: Multi-Store Unique Customers

Posted: Wed Mar 09, 2011 10:15 pm
by fido-x
The store_id is also in the order table (as is the customer_id), so you know which store(s) your customer(s) bought their product(s) from.

I've made some modifications to "system/library/customer.php" so you can get the customer's store with "$this->customer->getStoreId();". The attached zip file contains the modified file. Unpack it and copy the "customer.php" file to "system/library" (make sure you back-up the original first).

Re: Multi-Store Unique Customers

Posted: Wed Mar 09, 2011 10:59 pm
by cable
Thanks for the input everyone. Fido, thanks for hooking up the file.
Let me look into this further and will report back.

Thanks!

Re: Multi-Store Unique Customers

Posted: Thu Mar 10, 2011 12:07 am
by fido-x
Following on, using the above file, if you insert the following into "catalog/controller/account/login.php":

Code: Select all

if (!$this->config->get('config_store_id')) {
    if ($this->customer->getStoreId() != 0) {
        if ($this->customer->getStoreId() != $this->config->get('config_store_id')) {
            $this->load->model('setting/store');
            $store_info = $this->model_setting_store->getStore($this->customer->getStoreId());
            $this->redirect($store_info['url']);
        }
    }
} 
before line 28:

Code: Select all

unset($this->session->data['guest']); 
the customer will be redirected to the store at which they created their account.

Re: Multi-Store Unique Customers

Posted: Tue Mar 29, 2011 4:17 am
by arthursilva
Hi fido-x, I´ve made this modifications in my store, but if I enter some admin user, one can see the store from the other user.
Can this be hide, like one user just see you store back end?

Thanks.

Re: Multi-Store Unique Customers

Posted: Fri Apr 15, 2011 2:28 am
by Ljubo
I have tried with the new customer.php and advised modifications in login.php.

with user/pass of the 2nd store I tried to login into 1st store.
the result was simple redirection to the home page of the 2nd store.
I would prefer if I would be automatically logged in to the 2nd store, not simply redirected, but OK, this is better than it was in original.

I have logged in (into the 2nd store with its user/pass combination) and was interested what would happen if I try to click to a link for the 1st store.
the result was now that I was logged into the 1st store as a user of 2nd store.
this is not OK...

any solutions for this?

Re: Multi-Store Unique Customers

Posted: Fri Apr 15, 2011 4:38 pm
by fido-x
Ljubo wrote:I have tried with the new customer.php and advised modifications in login.php.

with user/pass of the 2nd store I tried to login into 1st store.
the result was simple redirection to the home page of the 2nd store.
I would prefer if I would be automatically logged in to the 2nd store, not simply redirected, but OK, this is better than it was in original.

I have logged in (into the 2nd store with its user/pass combination) and was interested what would happen if I try to click to a link for the 1st store.
the result was now that I was logged into the 1st store as a user of 2nd store.
this is not OK...

any solutions for this?
Yes. Insert the following into "catalog/controller/common/header.php" at around line 26:

Code: Select all

if ($this->customer->isLogged() && ($this->config->get('config_store_id') != $this->customer->getStoreId())) {
    $this->redirect(HTTP_SERVER . 'index.php?route=account/logout');
} 
Then, if a customer who is logged in to one store tries to move to another store where they are not registered, they will be logged out. Does that suit?

Re: Multi-Store Unique Customers

Posted: Fri Apr 15, 2011 5:18 pm
by Ljubo
Thank you!

Brief test and it is working.
You did help me!

all the best!

Re: Multi-Store Unique Customers

Posted: Wed Apr 20, 2011 12:17 am
by Ljubo
If I do not ask too much... I would need some more help.

I would like to have a module that is displayed but only to logged in customers. For the public, it should not be showed.

For example, a copy of information module, with several items inside.
Few of them to be visible to all (public and registered users), while all items to be visible only to logged in users.

All of this would be implemented to only one store of the multistored OC.

Any ideas please?

Re: Multi-Store Unique Customers

Posted: Thu Dec 22, 2011 11:13 pm
by rgros
fido-x wrote:
Ljubo wrote:I have tried with the new customer.php and advised modifications in login.php.

with user/pass of the 2nd store I tried to login into 1st store.
the result was simple redirection to the home page of the 2nd store.
I would prefer if I would be automatically logged in to the 2nd store, not simply redirected, but OK, this is better than it was in original.

I have logged in (into the 2nd store with its user/pass combination) and was interested what would happen if I try to click to a link for the 1st store.
the result was now that I was logged into the 1st store as a user of 2nd store.
this is not OK...

any solutions for this?
Yes. Insert the following into "catalog/controller/common/header.php" at around line 26:

Code: Select all

if ($this->customer->isLogged() && ($this->config->get('config_store_id') != $this->customer->getStoreId())) {
    $this->redirect(HTTP_SERVER . 'index.php?route=account/logout');
} 
Then, if a customer who is logged in to one store tries to move to another store where they are not registered, they will be logged out. Does that suit?
Hi!

I have tried this on the latest Open Cart version with no success, is there a possibility that some one could do the exact same thing for the new version?

THank you!

Re: Multi-Store Unique Customers

Posted: Thu Feb 23, 2012 11:31 am
by kingsley
Done it. Will be releasing shortly.

Re: Multi-Store Unique Customers

Posted: Wed Jul 11, 2012 7:12 pm
by ftrippie
Hi Kingsley (or anybody else)

did you release an upgrade to this solution in the end?
i would very much like to implement it for 1.5.1.3

cheers!

Re: Multi-Store Unique Customers

Posted: Wed Jul 11, 2012 11:27 pm
by ftrippie
BTW, I tried myself with some compare/copypaste.

I have 2 stores, store1=default with visible prices, store2=wholesale, with prices only visible at login.

It seems to be working if I try to login in store2, with a user from store1. It straight goes to the logout function (need to adapt the message a bit, so that people understand why they are suddenly logged out).

But if I try with a user from store2, to login store 1, it errors out with:
Fatal error: Call to undefined method ModelSettingStore::getStore() in /home/www/store1domain.com/catalog/controller/account/login.php on line 56

line 56 = $store_info = $this->model_setting_store->getStore($this->customer->getStoreId());

After reading some, I understand that the default store doesn't have a StoreID
(http://code.google.com/p/opencart/issues/detail?id=914)

what to do?

Re: Multi-Store Unique Customers

Posted: Wed Jul 11, 2012 11:46 pm
by ftrippie
Ah, I think I found it, the line should be:

$store_info = $this->model_setting_store->getStores($this->customer->getStoreId());

(getStores instead of getStore).

Seems to be working now, will do some more testing.

If anybody wants to know what I did, please reply to this thread..

Re: Multi-Store Unique Customers

Posted: Wed Sep 12, 2012 7:01 pm
by tommy smith
So we still can't just registered just 1 acc for any OC and using it login with other OC !?! follow above just transfer customer into the OC they are registered :(

Re: Multi-Store Unique Customers

Posted: Mon Oct 08, 2012 7:57 pm
by netops
http://www.opencart.com/index.php?route ... on_id=8651

Allows the same customer email address to generate unique customer accounts per store. As a result all transactions are completely isolated by store.

ie.

demo@demo.com = store_id 1 customer_id 1
demo@demo.com = store_id 2 customer_id 2
demo@demo.com = store_id 3 customer_id 3

Re: Multi-Store Unique Customers

Posted: Fri Feb 21, 2014 5:08 am
by wvervuurt
I know this thread is old, but I had the same problem and developed a simple, powerful and free extension to get this working. It doesn't use the store_id, but uses customer groups, so it's more powerful and flexible.

- Allows a set-up where one user has access to several stores, but not all of them (just check their customer group for every store they should have access to)
- Allows a set-up where different customer groups have access to the same store (just check all these customer groups for that store)

You can find the extension here: http://www.opencart.com/index.php?route ... n_id=16048