Magento-获取最新产品 [英] Magento - get current product

查看:85
本文介绍了Magento-获取最新产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的版式中有一个侧边栏块,该边栏块显示在不同的页面上.

I have a sidebar block in my layout that is being displayed on different pages.

在此块中,我有一个产品列表,当我在产品页面上时,我想选择当前产品.

In this block I have a list of products, and I want to select the current product when I'm on a product page.

我正在使用:

$current_product = Mage::registry('current_product');

以获取当前产品,但这仅在我第一次加载产品页面时有效.当我选择其他产品时,上面的代码将返回相同的值(第一个产品).

to get the current product, but this works only for the first time I'm loading the product page. When I select a different product the code above returns the same value (the first product).

我假设发生这种情况是因为我正在使用Magento缓存.我该怎么做才能获得正确的价值?

I'm assuming this happens because I'm using Magento cache. What can I do to get the right value?

当我使用时会发生同样的事情:

The same thing happens when I use:

$currentCategory = Mage::registry('current_category');

侧边栏是我在此处添加的导航模板: .. \ app \ design \ frontend \ default \ mytheme \ template \ catalog \ navigation \ page_left.phtml.

The sidebar block is a navigation template I've added here: ..\app\design\frontend\default\mytheme\template\catalog\navigation\page_left.phtml.

我使用以下XML将其添加到布局中:

I'm adding it to the layout with this XML :

<block type="catalog/navigation" name="left.navigation.block" as="left.navigation.block" template="catalog/navigation/page_left.phtml"/>

推荐答案

如果您不愿意使用从Mage_Catalog_Block_Navigation继承的自己的块类,则可以在其中设置自己的缓存信息(例如,取决于(在当前产品上),您可以通过在其布局定义中使用它来摆脱块的缓存:

If you're not willing to use your own block class inheriting from Mage_Catalog_Block_Navigation, in which you could set your own cache informations (to make it eg depending on the current product), you can get rid of the cache for your block by using this in its layout definition :

<block type="catalog/navigation" name="left.navigation.block" as="left.navigation.block" template="catalog/navigation/page_left.phtml">
    <action method="unsetData"><key>cache_lifetime</key></action>
</block>

这篇关于Magento-获取最新产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆