2012-04-07 42 views
0

我正在構建prestashop目錄,但只有登錄到客戶才能看到它。這可能嗎。這將是很好,如果內置prestashop登錄用於此..任何幫助表示讚賞。僅登錄prestashop目錄

+0

這可能工作其昂貴,雖然:([鏈接](http://www.presto-changeo.com/en/prestashop-modules/30-private-shop.html) – rashid 2012-04-10 07:47:57

回答

1

這很容易。

使用此代碼:

if(!self::$cookie->isLogged(true) AND in_array($this->step, array(1, 2, 3))) 
    Tools::redirect('authentication.php'); 

在你indexController的的預處理

+0

謝謝,得到它的工作沒有in_array ()部分,w是什麼意思btw? – rashid 2012-05-09 10:11:12

+0

還有一件事,這隻適用於客戶訪問主頁時,所有其他頁面通過直接鏈接工作訪問 – rashid 2012-05-09 10:43:30

1

這裏是我的解決方案,它的工作原理就像一個魅力,是一個非常簡單的辦法!

在類\的configuration.php(左右線114),它看起來像這樣

static public function get($key, $id_lang = NULL) 
{ 
    if ($id_lang AND isset(self::$_CONF_LANG[(int)$id_lang][$key])) 
     return self::$_CONF_LANG[(int)$id_lang][$key]; 
    elseif (is_array(self::$_CONF) AND key_exists($key, self::$_CONF)) 
     return self::$_CONF[$key]; 
    return false; 
} 

它改成這樣:

static public function get($key, $id_lang = NULL) 
{ 
    //Grab access to the $cookie which is already loaded in the FrontController as global $cookie; 
    global $cookie; 
    if ($id_lang AND isset(self::$_CONF_LANG[(int)$id_lang][$key])) 
     return self::$_CONF_LANG[(int)$id_lang][$key]; 
    elseif (is_array(self::$_CONF) AND key_exists($key, self::$_CONF)) 
     //If the system is trying to find out if Catalog Mode is ON, then return the configuration setting, 
     //but override it with the user logon status 
     if($key == 'PS_CATALOG_MODE') 
     { 
      return !$cookie->logged || self::$_CONF[$key]; 
     } 
     else 
     { 
      return self::$_CONF[$key]; 
     } 
    return false; 
} 

從本質上講,我想強制系統顯示「目錄模式「,並在他登錄時關閉此功能。

我可以保證這適用於v1.4.3.0和當前版本1.4.8.2的代碼(在這篇文章的時間)沒有改變,所以它應該在那裏工作。

+0

非常感謝,早期的解決方案只適用於索引/ home頁面,把它放在配置中更有意義! – rashid 2012-07-04 11:36:10

+0

我想帶人login.php,如果他們沒有登錄,並且沒有顯示目錄模式或任何東西,直到登錄。 – rashid 2012-11-07 11:07:26

+0

很好的答案!謝謝你的分享。 – JazZ 2016-04-02 18:48:53

2

我有一個建議。您可以使用PrestaShop 1.5中的客戶組功能,並且只允許登錄的客戶查看價格。對於分組在訪客中的每個客戶,他們都會在目錄模式下看到您的網站。

2

的Prestashop 1.5解決方案:

只需上傳原始文件:

classes\controller\FrontController.php 

到:

override/classes/controller/FrontController.php 

接下來,命名類。最終的代碼應該是這樣的:

class FrontController extends FrontControllerCore 
{ 
    public function init() 
    { 
     parent::init(); 
     if (!$this->context->customer->isLogged() && $this->php_self != 'authentication' && $this->php_self != 'password') 
     { 
      Tools::redirect('index.php?controller=authentication?back=my-account'); 
     } 
    } 
} 

最後一步是手動刪除下列文件,以便的Prestashop是意識到被覆蓋的類(它會自動重新生成)的:

cache/class_index.php 

而且voilà,在不覆蓋核心文件的情況下實現了功能。