Jump to content

Creating a custom category and pages


roroPrestashop

Recommended Posts

Hi Everyone! 

 

I have my own custom CMS that is being used to manage certain pages that Prestashop doesn't have built-in, as well as not having any modules out there, but I'd like to have these pages and categories appear in the Prestashop site.

I have already succeeded in created a custom pages, with their own controllers to show these PHP based pages. 

But what if I need a full category with sub-pages? 

 

Example:

The website will have a "press items" section. This section will have a grid of thumbnails of magazine covers. When an item is clicked you can go into this magazine to "read more".

The url structure should be like this:

http:/site.com/press   => the main grid of articles   (I have managed to do this part, but it's still considered a page and not a category)

http:/site.com/press/article   => the page that will hold the article content itself
(so basically, all of the "article pages" are dynamic)
 
* All of this content will be in a separate table in the database and be accessed from these pages. 
 
Is this possible?
 
Thanks in advance!
Edited by roroPrestashop (see edit history)
Link to comment
Share on other sites

For those who might be interested, I think I may have solved it. It might be a little sloppy, but it seems to work. 

 

By using the same idea as the “patch for module friendly urls” on line 782 of the Dispatcher class, I created an override of the method (“getController”) which looks at the URI (which is "press/press-item"), and checks if the first part of it is also a filename of a PHP file in the root folder (ie press.php) - which is part of my custom PHP page.

 

If the file does exist then apparently it is a custom subdirectory and since there is another part to the URI (the second part), (ie “..../press-item”) then “press” is a category and “press-item” is in that category. So it will load my custom controller and I save the second part as a GET var to be read from within the controller. 

 

This is what I added after the "if" statement in Dispather.php:

if (preg_match('#([a-z0-9_]+)/([a-z0-9_]+)$#i', $uri, $m)) {
   if(is_file(_PS_ROOT_DIR_.'/'.$m[1].".php")) {
      $controller = $m[1];
      $_GET['item'] = $m[2];
   }            
}

If anyone understands this and maybe has another suggestion, I'll be happy to hear!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...