Magento “$this->loadLayout()” 在 AJAX 中消耗很长时间


Magento “$this->loadLayout()” consumes long time in AJAX

我是magento的新手,我想在我的新网站上添加"AJAX购物车"功能。然后我按照本教程进行操作。http://excellencemagentoblog.com/blog/2011/10/04/magento-add-product-to-cart-ajax/

但我注意到,它花了很长时间才做出回应。原因是"$this->loadLayout()"在以下代码中消耗了很长时间。

$this->loadLayout();
$sidebar = $this->getLayout()->getBlock('cart_sidebar')->toHtml();

在谷歌上呆了一段时间后,我将代码更改为休耕。

$sidebar = $this->getLayout()->createBlock('checkout/cart_sidebar')->setTemplate('path_my _template.phtml')->toHtml();

然后时间从 20 秒减少到 5 秒。除了 url 之外,两个代码中的输出相同。 我正在打印(回显)模板中的"结帐 URL"。在第一个代码中,URL 以"?__SID"结尾,但在第二个代码中不是。

有人知道为什么会这样吗?我想减少项目添加时间和获取安全 URL。

我已经通过将代码更改为休耕来解决这个问题。

$this->getLayout()->createBlock('page/html');
$sidebar = $this->getLayout()->createBlock('checkout/cart_sidebar')->setTemplate('path_my _template.phtml')->toHtml();