我遇到了 Tinybrick 所说的“高级打洞”的情况,但我似乎无法让它工作。我们最近安装了 Aheadworks 的订阅和定期付款扩展。此扩展允许客户订阅他们定期购买的产品,并扩展了 PayPal 定期配置文件的功能。为此,产品 View 页面上的 addtocart block 必须是动态的。根据客户是否登录以及相关产品的具体详细信息,确定 addtocart block 中显示的内容。
使用 Lightspeed 打洞,我已经能够填充页面上的各种动态 block (顶部链接、标题购物车、相关产品等)。该 block 的问题在于它取决于 Mage::registry('current_product')
值。当 Lightspeed 返回缓存页面时,它不会运行完整的 Magento 代码,并且不会设置 current_product
注册表值。我找不到方法来完成这项工作。
我向 Tinybrick 发送了一封电子邮件并收到了以下回复:
For advanced hole punching like this, you would have to make a call via API / SOAP in the Controller. Basically, you would make a call for whatever information you need, then use that information to display your dynamic content. I have personally never done it like this, but was informed by our lead developer that it can be done.
我回复要求提供示例或更多信息,但尚未收到回复。我想我应该在这里抛出一些东西,看看是否有人有这方面的经验并可以提供一些帮助。
最佳答案
当lightspeed.php
在var/lightspeed
目录中看到相应的缓存文件时,它会加载它并解析。现在它发现,某些内容需要是动态的。因此,lightspeed.php
通过 Mage::run()
向 Magento 发出了一个虚假的 GET 请求,并更改了之前的 $_REQUEST['URI']
。看一下下面的代码:
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];
您可以在此处查看我如何将 $_SERVER['REQUEST_URI']
复制到 $_SERVER['originalRequestUri']
。我们接下来看一下
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);
}
耶!现在我们在注册表中有current_product
。您可以创建所需的 block 。
关于php - 使用 Tinybrick 的 Lightspeed 进行高级打洞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14265798/