Product page as homepage in Opencart

一笑奈何 提交于 2019-12-07 23:23:37

问题


I have only one product on my opencart and I want this product just to be in the homepage so that the customer will no longer go to any page just to buy the product. How can I make this product as default homepage? or How can I make the url default to the url of this product? I'm using opencart. I've tried to override the layout of the product but it didn't work. "Opencart Admin > Product > Porduct Page > Layout Tab > Override (Home)".


回答1:


Both of these require you to edit your /catalog/controller/common/home.php and place the code after the public function index() { line, changing 123 to your products id

v1.5.x

$this->redirect($this->url->link('product/product', 'product_id=123'));

v2.x + v3.x

$this->response->redirect($this->url->link('product/product', 'product_id=123'));



回答2:


If you want to show the homepage URL and display the product you can edit the /index.php file and add the following code

if (!isset($request->get['route']) || $request->get['route'] == 'common/home')   {
    $request->get['route'] = 'product/product';
    $request->get['product_id'] = 1;
}

Add it below the code

// SEO URL's
$controller->addPreAction(new Action('common/seo_url'));

You will need to change the product_id to the id of your product. e.g. $request->get['product_id'] = 12;




回答3:


In the case of redirect the particular product page as home page is pretty good but you need to change the redirection URL while you are changing the product...

It is simple ->>>>>>>> $this->redirect($this->url->link('product/product', 'product_id=123'));

But just use featured Category in your home page...

Module->Featured->Limit & enable..

Product->edit(particular product)->special->leave price field and fix start date and end date...

System->design->layout->home->edit->add featured module in content top set priority 1




回答4:


OpenCart 2.3

file catalog/controller/startup/seo_url.php after

// Add rewrite to url class
        if ($this->config->get('config_seo_url')) {
            $this->url->addRewrite($this);
        }

insert

if ( !isset($this->request->get['_route_']) && !isset($this->request->get['route']))   {
            $this->request->get['route'] = 'product/product';
            $this->request->get['product_id'] = 42;
        }

if ( isset($this->request->get['route']) && $this->request->get['route'] == 'common/home' ){
            $this->request->get['route'] = 'product/product';
            $this->request->get['product_id'] = 42;

        }

You will need to change the product_id to the id of your product. e.g. $this->request->get['product_id'] = 102;



来源:https://stackoverflow.com/questions/28801331/product-page-as-homepage-in-opencart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!