如何使用CMS页面作为PrestaShop的首页,并将默认商店索引设置为/ someurl?

问题描述:

我已将此自定义IndexController.php设置为/ override/controllers/front,将CMS页面作为索引(请参阅$id_cms)。如何使用CMS页面作为PrestaShop的首页,并将默认商店索引设置为/ someurl?

class IndexControllerCore extends FrontController 
{ 
    //public $php_self = 'index'; 

    /** 
    * Assign template vars related to page content 
    * @see FrontController::initContent() 
    */ 
    /*public function initContent() 
    { 
     parent::initContent(); 
     $this->addJS(_THEME_JS_DIR_.'index.js'); 

     $this->context->smarty->assign(array('HOOK_HOME' => Hook::exec('displayHome'), 
      'HOOK_HOME_TAB' => Hook::exec('displayHomeTab'), 
      'HOOK_HOME_TAB_CONTENT' => Hook::exec('displayHomeTabContent') 
     )); 
     $this->setTemplate(_PS_THEME_DIR_.'index.tpl'); 
    }*/ 

    public $php_self = 'cms'; 
    public $assignCase; 
    public $cms; 

    /** @var CMSCategory */ 
    public $cms_category; 
    public $ssl = false; 

    public function canonicalRedirection($canonicalURL = '') 
    { 
     if (Tools::getValue('live_edit')) { 
      return; 
     } 
     if (Validate::isLoadedObject($this->cms) && ($canonicalURL = $this->context->link->getCMSLink($this->cms, $this->cms->link_rewrite, $this->ssl))) { 
      parent::canonicalRedirection($canonicalURL); 
     } elseif (Validate::isLoadedObject($this->cms_category) && ($canonicalURL = $this->context->link->getCMSCategoryLink($this->cms_category))) { 
      parent::canonicalRedirection($canonicalURL); 
     } 
    } 

    public function setMedia() 
    { 
     parent::setMedia(); 

     if ($this->assignCase == 1) { 
      $this->addJS(_THEME_JS_DIR_.'cms.js'); 
     } 

     $this->addCSS(_THEME_CSS_DIR_.'cms.css'); 
    } 

    /** 
    * Assign template vars related to page content 
    * @see FrontController::initContent() 
    */ 
    public function initContent() 
    { 
     parent::initContent(); 

     $id_cms = 6; 
     $this->cms = new CMS($id_cms, $this->context->language->id); 

     $parent_cat = new CMSCategory(1, $this->context->language->id); 
     $this->context->smarty->assign('id_current_lang', $this->context->language->id); 
     $this->context->smarty->assign('home_title', $parent_cat->name); 
     $this->context->smarty->assign('cgv_id', Configuration::get('PS_CONDITIONS_CMS_ID')); 

     if (isset($this->cms->id_cms_category) && $this->cms->id_cms_category) { 
      $path = Tools::getFullPath($this->cms->id_cms_category, $this->cms->meta_title, 'CMS'); 
     } elseif (isset($this->cms_category->meta_title)) { 
      $path = Tools::getFullPath(1, $this->cms_category->meta_title, 'CMS'); 
     } 

     $this->context->smarty->assign(array(
      'cms' => $this->cms, 
      'content_only' => (int)Tools::getValue('content_only'), 
      'path' => $path, 
      'body_classes' => array($this->php_self.'-'.$this->cms->id, $this->php_self.'-'.$this->cms->link_rewrite) 
     )); 

     if ($this->cms->indexation == 0) { 
      $this->context->smarty->assign('nobots', true); 
     } 

     $this->setTemplate(_PS_THEME_DIR_.'cms.tpl'); 
    } 

现在我的问题是:如何将原始商店索引呈现为像/ store这样的网址?

我不认为有一个简单的方法来搅乱内部Prestashop Dispatcher来声明索引的基础URL。我只是简单地看了一下核心类,不知道如何轻松处理。

如果我必须这样做,我会创建一个新的cms页面或新的自定义控制器。并简单地在.htaccess根重定向到当前页:

RewriteBase/
RewriteRule ^$ /store [L,R=301] 

# ~~start~~ Do not remove this comment, Prestashop will keep automatically 
# [...] 
+0

我会回答与我刚刚实施的解决方案myselft:定制控制器+设置> SEO和URL –

1)创建定制控制器/控制器/前

class myStoreIndexController extends FrontController { 

    public $php_self = 'myStoreIndex'; 

    /** 
    * Assign template vars related to page content 
    * @see FrontController::initContent() 
    */ 
    public function initContent() { 
    parent::initContent(); 
    $this->addJS(_THEME_JS_DIR_.'index.js'); 
    $this->context->smarty->assign(array(
     'HOOK_HOME' => Hook::exec('displayHome'), 
     'HOOK_HOME_TAB' => Hook::exec('displayHomeTab'), 
     'HOOK_HOME_TAB_CONTENT' => Hook::exec('displayHomeTabContent') 
    )); 
    $this->setTemplate(_PS_THEME_DIR_.'index.tpl'); 
    } 
} 

2)进入PS控制面板菜单:设置> SEO &的url ,点击“添加新的页面”,然后选择作为网页,我们的“myStoreIndexController”,设置所需的标题和meta终于进入“存储”作为友好的URL并保存

enter image description here

3)享受CMS主页+店在您的自定义路径

+0

这就是我说的是,当我说“我会创建一个新的cms页面或新的自定义控制器。“ )。您是否将'www.yoursite.com /'基地重定向到'.htaccess'中的'/ store'? –

+0

是的,我已经完成了它,然后再阅读你的答案:)我写在这里,因为我没有找到PS论坛清晰的解决方案。不,我不想重定向根,因为我有我的cms页面作为根。我仍在测试此解决方案是否按预期工作,而不会破坏某些功能或需要更多工作 –