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

时间:2016-06-13 20:17:18

标签: prestashop prestashop-1.6

我已将此自定义IndexController.php设置为/ override / controllers / front以将CMS页面作为索引(请参阅$id_cms)。

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这样的网址?

2 个答案:

答案 0 :(得分:1)

1)在/ controllers / front

中创建自定义控制器
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&网址,点击"添加新页面"然后选择我们的" myStoreIndexController",设置你需要的标题和元素,最后输入" store"作为友好的网址并保存

enter image description here

3)在自定义路径中享受cms主页+商店

答案 1 :(得分:0)

我不认为有一种简单的方法可以让内部的Prestashop Dispatcher为索引声明一个基本网址。我只是快速浏览了核心课程,并且无法弄清楚如何轻松处理这个问题。

如果我必须这样做,我会创建一个新的cms页面或一个新的自定义控制器。只需将.htaccess根目录重定向到此页面:

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

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