1つのプロジェクトでopencartを使用しています。
すべてが正常に機能していますが、ログインするまでホームページの表示を停止するオプションを見つけることができません。
実際、これはプロジェクトの要件であり、LOGINまで誰も家を見ることができません。
OPEN CARTでこれを行う方法はありますか?
ありがとう
私が知っている組み込みのものは何もありませんが、あなたはそれを自分で行うことができます。@CarpeNoctumDCの質問に対する回答に基づいて、掘り下げる必要があるかもしれませんが、これで始めることができます。
system / library / customer.php
public function isLogged() { ... }
カタログ/コントローラー/common/home.php
if (!$this->customer->isLogged()) {
// login page
exit;
}
これはテストされていませんが、正しい方向を示す必要があります。
(OpenCart 1.4.9.x)
これを次の場所に保存します:catalog / controller / common / check_login.php
<?php
class ControllerCommonCheckLogin extends Controller {
public function index() {
if (!$this->customer->isLogged()) {
// Require to be logged in
$ignore = array(
'account', 'payment'
);
$match = false;
if (isset($this->request->get['route'])) {
foreach ($ignore as $i) {
if (strpos($this->request->get['route'], $i) !== false) {
$match = true;
break;
}
}
}
// Show site if logged in as admin
$this->load->library('user');
$this->registry->set('user', new User($this->registry));
if (!$this->user->isLogged() && !$match) {
return $this->forward('account/login');
}
}
}
}
?>
/index.phpを編集します
探す:
// Maintenance Mode
$controller->addPreAction(new Action('common/maintenance/check'));
後に追加:
// Login Check
$controller->addPreAction(new Action('common/check_login'));
基本的に、メンテナンスチェックと同じロジックを使用します...大きな違いは、文字列内の「account」という単語を検索することです...見つかった場合は、ページを表示できますが、そうでない場合は、ログインページにリダイレクトされます..。。
登録が必要な場合は、「ログイン」の代わりに「アカウント」という単語を使用してください...すべてのアカウントページはすでにlogginをチェックしているので、心配する必要はありません...
繰り返しになりますが、テストされていないため、1つまたは2つの調整が必要になる場合がありますが、コードをドロップすることで機能するはずです。
opencart1.5.3のcheck_login.php
<?php
class ControllerCommonCheckLogin extends Controller {
public function index() {
// Require to be logged in
if (!$this->customer->isLogged()) {
// Require to be logged in
$ignore = array(
'account','payment'
);
$match = false;
if (isset($this->request->get['route'])) {
foreach ($ignore as $i) {
if (strpos($this->request->get['route'], $i) !== false) {
$match = true;
break;
}
}
}
// Show site if logged in as admin
$this->load->library('user');
$this->user = new User($this->registry);
if (!$this->user->isLogged() && !$match) {
$this->redirect($this->url->link('account/login'));
}
}
}
}
?>
これを実行する正しい方法は、開くことです
/catalog/controller/common/home.php
public function index() {
コードの上部にあり、その後に配置します
if(!$this->customer->isLogged()) {
$this->session->data['redirect'] = $this->url->link('common/home');
$this->url->redirect('account/login', '', 'SSL');
}
public function index() {
これを適切に行う方法がわからない場合は、後の最初の数行を見てください。
/catalog/controller/account/account.php
ホームコントローラーのコードをのcommon/home
代わりに設定するaccount/account