When lightspeed.php
sees a corresponding cache file in var/lightspeed
directory, it loads it and parses. Now it sees, that some content needs to be dynamic. So lightspeed.php
makes a fake GET request to Magento via Mage::run()
with changed $_REQUEST['URI']
before. Take a look at the following code:
lightspeed.php:
self::report("attempting to retrieve hole punched content from {$data[2]}");
$_SERVER['originalRequestUri'] = $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URI'] = self::$request_path . "/" . $data[2];
You can see here how I copy $_SERVER['REQUEST_URI']
to $_SERVER['originalRequestUri']
. Let's go next and take a look at
HoleController.php:
$originalRequest = new Mage_Core_Controller_Request_Http('http://example' . $_SERVER['originalRequestUri']);
$originalRequest->setPathInfo()->setDispatched(false);
Mage::getModel('core/url_rewrite')->rewrite($originalRequest);
$params = explode('/', $originalRequest->getPathInfo());
/* IF YOU HAVE SOME ADDITONAL PARAMS PASSED AS /color/1/size/2,
THIS PARAMS SHOULD BE ALSO PARSED AND SET TO REQUEST OBJECT
for ($i = 3, $l = sizeof($params); $i < $l; $i+=2) {
$originalRequest->setParam($params[$i], isset($params[$i + 1]) ? $params[$i + 1] : '');
}
*/
if ($params[1] == 'product') { // if parsed URL is product view page URL
$productId = $originalRequest->getParam('id');
$product = Mage::getModel('catalog/product')->load($productId);
Mage::register('current_product', $product);
}
Yay! Now we have current_product
in registry. You're able to create a block you need.