No Guests : Customer Login required like Admin Login

Open to all! Ask other shopowners for help.
Nigel
Contributor
Posts: 114
Joined: Mon Jan 11, 2021 1:39 am
Phoenix Version:
Has thanked: 29 times
Been thanked: 8 times

No Guests : Customer Login required like Admin Login

Post by Nigel »

No Guests : Customer Login required like Admin Login

I would like the customer landing page to be a login like the admin.
I have spent the past few hours trying to find info on the forum and also looking through the files.

Can a customer go straight to the login.php like an Admin does and all areas of the cart require a successful login ?


Customers are current active customers whose online accounts would be initially created for them and their login details issued to them. This is normal practise in my industry.

I'm looking to create an ordering portal for trade customers who we currently contact via telesales.

Thanks for any advice / input.

Nigel


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: No Guests : Customer Login required like Admin Login

Post by ecartz »

Code: Select all

class hook_shop_siteWide_loginRequired {

  public function listen_siteWideStart() {
    $page = basename(Request::get_page());
    if (('create_account.php' !== $page) && !Text::is_prefixed_by($page, 'log')) {
      Login::require();
    }
  }

}
User avatar
zipurman
Builder
Posts: 540
Joined: Tue Oct 13, 2020 5:20 pm
Phoenix Version: v
Has thanked: 93 times
Been thanked: 162 times

Re: No Guests : Customer Login required like Admin Login

Post by zipurman »

In case you need help creating the hook above:
zipurman
-----------
Nigel
Contributor
Posts: 114
Joined: Mon Jan 11, 2021 1:39 am
Phoenix Version:
Has thanked: 29 times
Been thanked: 8 times

Re: No Guests : Customer Login required like Admin Login

Post by Nigel »

My site is set to override on the templates section.
does the hook still go into default or overrides ?

Am I right in thinking a copy of the htaccess in the templates/default should also exist in templates/override ?
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: No Guests : Customer Login required like Admin Login

Post by ecartz »

Nigel wrote: Tue Aug 10, 2021 9:32 am My site is set to override on the templates section.
does the hook still go into default or overrides ?
The only time it would matter would be if there were two hooks, one in each place. Then override should defeat default. But if there's only one, then either place should work.
Nigel wrote: Tue Aug 10, 2021 9:32 am Am I right in thinking a copy of the htaccess in the templates/default should also exist in templates/override ?
If only there were a reference implementation, then you could just look there: Core provides three files inside the override directory tree, and all three should exist in your installation.
Nigel
Contributor
Posts: 114
Joined: Mon Jan 11, 2021 1:39 am
Phoenix Version:
Has thanked: 29 times
Been thanked: 8 times

Re: No Guests : Customer Login required like Admin Login

Post by Nigel »

ecartz wrote: Tue Aug 10, 2021 10:56 am
Nigel wrote: Tue Aug 10, 2021 9:32 am My site is set to override on the templates section.
does the hook still go into default or overrides ?
The only time it would matter would be if there were two hooks, one in each place. Then override should defeat default. But if there's only one, then either place should work.
Nigel wrote: Tue Aug 10, 2021 9:32 am Am I right in thinking a copy of the htaccess in the templates/default should also exist in templates/override ?
If only there were a reference implementation, then you could just look there: Core provides three files inside the override directory tree, and all three should exist in your installation.
My version didn't have the htaccess in there.
Is it recommended to use the github as a reference, if that's what you're implying ?
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: No Guests : Customer Login required like Admin Login

Post by ecartz »

Nigel wrote: Tue Aug 10, 2021 11:09 am My version didn't have the htaccess in there.
They should have been added in the 1.0.7.13 update, which is what created the override folder.
Nigel wrote: Tue Aug 10, 2021 11:09 am Is it recommended to use the github as a reference, if that's what you're implying ?
Yes. In a normal install, the only files that should change from the GitHub versions are the configure.php files. All other modified files should be in one of the override places:
  • admin/includes/classes/override
  • includes/system/override
  • templates/override
It is possible to create an alternative to the override template, which could be named almost anything other than default or override. New files (that don't conflict with core files) could go anywhere.

Note that English language files used to be modified in place but now should go under templates/override/includes/languages in catalog. Hopefully you don't have any reason to modify the language files under admin or install. This is covered at How to Change Text

Modules don't really work well with that system, so should generally be copied and renamed. The ot_shipping module is an exception, as it won't override all the behavior if renamed. One of these days, I should probably fix that.
Nigel
Contributor
Posts: 114
Joined: Mon Jan 11, 2021 1:39 am
Phoenix Version:
Has thanked: 29 times
Been thanked: 8 times

Re: No Guests : Customer Login required like Admin Login

Post by Nigel »

I created a php file called loginRequired.php

Code: Select all

<?php

class hook_shop_siteWide_loginRequired() {

  public function listen_siteWideStart() {
    $page = basename(Request::get_page());
    if (('create_account.php' !== $page) && !Text::is_prefixed_by($page, 'log')) {
      Login::require();
    }
  }

}
I placed it in templates/default/includes/hooks/shop/siteWide with no success. Just error 500.
I then tried by adding hooks/shop/siteWide to the override section as that's how it's set in myStore. Still no joy.
I've watched Zipurman's video many times and still can't see what I'm missing.
User avatar
zipurman
Builder
Posts: 540
Joined: Tue Oct 13, 2020 5:20 pm
Phoenix Version: v
Has thanked: 93 times
Been thanked: 162 times

Re: No Guests : Customer Login required like Admin Login

Post by zipurman »

Nigel wrote: Tue Aug 10, 2021 10:48 pm I've watched Zipurman's video many times and still can't see what I'm missing.
What version of Phoenix are you running?

What version of PHP are you using?

What does the error log say, as with a 500 error you should have some log entries?
zipurman
-----------
Nigel
Contributor
Posts: 114
Joined: Mon Jan 11, 2021 1:39 am
Phoenix Version:
Has thanked: 29 times
Been thanked: 8 times

Re: No Guests : Customer Login required like Admin Login

Post by Nigel »

Installed Version: CE Phoenix v1.0.8.5

PHP Version 7.3.27 (Zend 3.3.27)

[Tue Aug 10 23:52:38 2021] [error] [client xxx.xxx.xxx.133:0] PHP Parse error: syntax error, unexpected '(', expecting '{' in /home/sites/blahblah.com/public_html/top/templates/override/includes/hooks/shop/siteWide/loginRequired.php on line 3


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply