Asked  9 Months ago    Answers:  5   Viewed   248 times

I am having http://example.com/index.php as my home page. My Category Page URL is http://example.com/index.php?id_category=10&controller=category

Now, I need to redirect my homepage to Category Page. I tried in Preferences > SEO & URL's > Set Shop URL > Base URI as index.php?id_category=10&controller=category

Now, the page is redirecting to my Category Url but the page is not opening. the URL is showing like this http://example.com/index.php?id_category=10&controller=category/index.php?

 Answers

3

You are doing it the wrong way. Do it as followed:

A) Easy but not recommended Way:

1) Open Controllers/IndexController.php

2) Modify function initContent as below :

public function initContent()
{

   parent::initContent();
   Tools::redirect('index.php?id_category=10&controller=category');
   $this->context->smarty->assign('HOOK_HOME', Hook::exec('displayHome'));
   $this->setTemplate(_PS_THEME_DIR_.'index.tpl');

}

B) Recommended Way:

1) Copy Controllers/IndexController.php to override/Controllers/ folder 2) Open the copied file and edit as below:

class IndexController extends IndexControllerCore 
{

    public function initContent()
    {
       Tools::redirect('index.php?id_category=10&controller=category');

    }
}

3) Save the file and go to cache folder. Find class_index.php , if it is there then delete it. Then check the site if it works fine.

Notes :

1) The above code is to give you idea, it may or may not work. Please do adjustment according to your needs.

2) In latest versions of Prestashop, all classes are indexed in the class_index.php file. so if you made any override of a controller or class, it may not work until you delete that file. When a new request is made to server, PS automatically regenerate that file for you.

Hope this will help.

Monday, September 13, 2021
 
ollien
 
3

Revert all modify that you have done :).

Try this way:

For example, this is core module file rootofps/modules/vpages/vpages.php

class VPages extends Module {
   public function __construct(){
       $this->name = 'vpages';
       $this->author = 'you';
       $this->tab = 'front_office_features';
       $this->version = '1.0.0';
       $this->controllers = array('dpage');

       parent::__construct();
   }

   // This is the function in your core module file (not in controller)
   public function install(){
       return parent::install() && $this->registerHook('moduleRoutes')
   }

   public function hookModuleRoutes($params){
      $my_link = array(
          'vpages' => array(
              'controller' => 'dpage',
              'rule' => 'flower-deliveries{-:id_country}{-:country}{-:city}.html',
              'keywords' => array(
                  'id_country' => array('regexp' => '[0-9]+', 'param' => 'id_country'),
                  'country' => array('regexp' => '[w]+', 'param' => 'country'),
                  'city' => array('regexp' => '[w]+', 'param' => 'city'),
               ),
               'params' => array(
                   'fc' => 'module',
                   'module' => 'vpages'
               )
           )
        );
        return $my_link;
    }
}

Now the controller rootofps/modules/vpages/controllers/front/dpage.php

class VpagesDpageModuleFrontController extends ModuleFrontController {
    public function init(){
        parent::init();
        $this->setTemplate('dapage.tpl');
    }
}

And now the view rootofps/modules/vpages/views/templates/front/dpage.tpl

id_country = {$smarty.get.id_country}<br>
country = {$smarty.get.country}<br>
city={$smarty.get.city}<br>

This 'skeleton' works at 100% :), by the way, notice that if you give an url like this mydomain.com/flower-deliveries?id_country=1&country=italy&city=rome PrestaShop will not transform your url in a clearly url as you want. But an url like this mydomain.com/flower-deliveries-2-italy-rome.html will be routes properly :)

Thursday, April 1, 2021
 
1

Well after looking around and asking on the Prestashop forums, I've been told there is no easy-straightforward-hack-free solution to achieve this. Because apparently the name chosen for the category is used to construct the url. This would mean editing many core files just to put a special character via the back-end>categories fields, which is illogic.

So I just hardcoded this into the file modulesps_mainmenu*ps_mainmenu.tpl* : it works for my case.

 {* {$node.label} *}


               {if $node.label|strstr:"and"}
                  {assign var="teststring" value=$node.label}
                  {assign var="testsplit" value="and"|explode:$teststring}
                  {$testsplit[0]} <br/> and {$testsplit[1]}
              
                  {elseif $node.label|strstr:","}

                  {if substr_count($node.label, ",") > 1 }

                    {assign var="teststring" value=$node.label}

                    {assign var="label" value=","|explode:$teststring}

                    {$label[0]},<br/>{$label[1]}, {$label|@end}
                    

                  {/if}

I'm sure someone PHP/Smarty savy could do this in a few lines and much nicer ( let me know please! ) but it works for me. (adding <br/> in some cases)

Thursday, April 1, 2021
 
MDDY
 
2

In the Area folder there is a file by name AreaNameAreaRegistration deriving from AreaRegistration, it has a function RegisterArea which sets up the route.

Default route in an Area is AreaName/{controller}/{action}/{id}. Modifying this can set an area as default area. For example I set the default route as {controller}/{action} for my requirement.

public class UIAreaRegistration : AreaRegistration
{
        public override string AreaName
        {
            get
            {
                return "UI";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "UI_default",
                "{controller}/{action}/{id}", //******
                new {controller = "Home", action = "Index", id = UrlParameter.Optional}
            );
        }
    }
Saturday, October 2, 2021
 
Terry
 
1

I would say, that solution here should be surprisingly simple:

  • Remove the view name 'home'. In fact change it to '' (empty string)

There is a working plunker with this change?

.state('home', {
      url: '/home',
      views: {
          // instead of this
          // 'home': {

          // use this
          '': {
              templateUrl: 'tpl.home.html',
              controller: 'HomeCtrl',
          }
      }
}) 

Why? Because most likely the index.html would look like this:

<body ng-app="myApp" >

    ...
    <ion-nav-view></ion-nav-view>

</body>

And that means that the view name is "", almost like <ion-nav-view name=""></ion-nav-view>

Check that in action here

EXTEND based on the question extension

if we use ionic-like approach with separated file and module for controllers:

// inside of the index.html
<script src="js/controllers.js"></script>

// the controller.js
angular.module('starter.controllers', [])

We must be sure, that our app.js does contain that module as well:

angular.module('myApp', [
   'ionic',
   'starter.controllers' // this is a MUST
])
Monday, December 27, 2021
 
CCoder
 
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :