cancel
Showing results for 
Search instead for 
Did you mean: 

Getting the layered navigation and toolbar ouside Magento

Getting the layered navigation and toolbar ouside Magento

Hi.

Im trying to get the layered navigation of a category links from a php that is outside magento.

I can create all of the category html, but the problem is that the layered links are created with the params of frontcontroller (at the same way of the toolbar links).

If i have a filter selected the creation of layered links doesnt take account of it, and also the layered links havent the category url...

I try to recreate the frontcontroller of the category page inside magento on my php ouside that, but i haven success... Even i recreate the $_SERVER, but the controller seems to not find a router...

In the php if i use mage::run, it do the operation of calcule correctly but mage::run makes the response and isnt i want because i need an xml output only of layered navigation.

If i use mage::app i can get the category html, but the controler isnt calculated correctly although is the same $_SERVER[request_uri] and havent correct links. The front controller havent action... 

 

In the frontcontroller request i see two differences: in magento dispathed is true, but in the php no, and in magento de request_uri are rewrited to catalog/category/view/id/7?color=99 while in the php not hombre.html?color=99

 

Im missing anything, i need to initialize the front controller? o reinitialize???

Or there a different way to get the layered navigation from outside magento??

1 REPLY

Re: Getting the layered navigation and toolbar ouside Magento

I found the problem and the solution...

On start magento it calls to rewrite the URL with the aim to get converted friendly url on a route url...

hombre.html?color=99 is converted on catalog/category/view/id/7?color=99

So the first is to call Mage::getModel('core/url_rewrite')->rewrite();  and now our frontcontroller request have the URL converted correctly.

Before that the frontendcontroller is inited executing the function match in all of its routers to try to find a controller and an action...

$frCont = Mage::app()->getFrontController();
foreach ($frCont->getRouters() as $router) {
   if ($router->match($frCont->getRequest())) {
       break;
   }
}

 

With that two steps i have the frontcontroller initialized like if i access to the url "hombre.html?color=99" but in fact im on another php in my services folder.

 

But the match function after initialize the frontcontroller and get the router, action, and route, dispatch the action by default, so it generate all the html output and cannot work with layouts... So i create a local copy of the class Mage_Core_Controller_Varien_Router_Standard and i have updated the function match:

public function match(Zend_Controller_Request_Http $request){

.

.

.

    $controllerInstance->dispatch($action);

    return true;

}

 

for this one

public function match(Zend_Controller_Request_Http $request, $dispatchAction = true){

.

.

.

   if($dispatchAction==true){
       $controllerInstance->dispatch($action);
    }

   return true;

}

 

So in my service php i have that code:

   Mage::getModel('core/url_rewrite')->rewrite();
   $frCont = Mage::app()->getFrontController();
   foreach ($frCont->getRouters() as $router) {
     if ($router->match($frCont->getRequest(),false)) {
       break;
     }
   }

 

And i have the frontcontroller initialized and the action,router,params, etc assigned like if i access from the catalog URL but withouth dispatching the action, and then i can write the objects i want with the layout object.

 

Hope it helps anyone.