Magento 最近查看的产品
Magento recently viewed products
我试过的。刚看到商品就显示出来,结果什么都没有:
<?php $_recentlyViewed =
Mage::getSingleton('Mage_Reports_Block_Product_Viewed')-> getItemsCollection(); ?>
<?php foreach ($_recentlyViewed as $_recentlyProduct): ?>
<?php var_dump($_recentlyProduct); ?>
<?php endforeach; ?>
接下来,它试图显示默认块,然后我什么也没得到。在 local.xml 中我添加了:
<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_product_view>
<reference name="content">
<reference name="product.info">
<block type="reports/product_viewed" name="product.recently.viewed" as="product_recently_viewed" template="reports/product_viewed.phtml"/>
<block type="poll/activePoll" name="right.poll" after="product_recently_viewed">
<action method="setPollTemplate"><template>poll/active.phtml</template><type>poll</type></action>
<action method="setPollTemplate"><template>poll/result.phtml</template><type>results</type></action>
</block>
</reference>
</reference>
</catalog_product_view>
和
<?php echo $this->getChildHtml('product_recently_viewed'); ?>
在view.phtml,但我还是一无所获。
我查看了mysql里面的table,里面有最后浏览过的商品的记录。所以我的问题是,是什么让我错了?有什么想法吗?
尝试使用 local.xml 文件中的 xml 代码:
<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_product_view>
<reference name="product.info">
<block type="reports/product_viewed" name="product.recently.viewed" as="product_recently_viewed" template="reports/product_viewed.phtml"/>
<block type="poll/activePoll" name="right.poll" after="product_recently_viewed">
<action method="setPollTemplate"><template>poll/active.phtml</template><type>poll</type></action>
<action method="setPollTemplate"><template>poll/result.phtml</template><type>results</type></action>
</block>
</reference>
</catalog_product_view>
</layout>
这是因为您不需要嵌套引用即可在模板中注入内容。如果这不起作用,那么唯一的原因就是您在 catalog.xml 文件中没有 product.info
句柄,因为大多数主题都自定义了它。您需要检查主题的 catalog.xml。
对于您显示的 PHP 代码,块不是这样调用的。 getSingleton
方法保留用于以单例方式加载模型。但是,您使用完全限定的 class 名称传递它的方式,无论如何您都可能获得该块的对象。请记住它以备将来参考。块在需要时通过 Magento 的布局模型实例化。它们应该以这种方式使用。
你已经使用了 getSingleton 尝试使用这个:
<?php $_recentlyViewed =
Mage::getModel('Mage_Reports_Block_Product_Viewed')-> getItemsCollection(); ?>
<?php foreach ($_recentlyViewed as $_recentlyProduct): ?>
<?php var_dump($_recentlyProduct); ?>
<?php endforeach; ?>
通过使用getModel,我认为你的工作可以实现
我试过的。刚看到商品就显示出来,结果什么都没有:
<?php $_recentlyViewed =
Mage::getSingleton('Mage_Reports_Block_Product_Viewed')-> getItemsCollection(); ?>
<?php foreach ($_recentlyViewed as $_recentlyProduct): ?>
<?php var_dump($_recentlyProduct); ?>
<?php endforeach; ?>
接下来,它试图显示默认块,然后我什么也没得到。在 local.xml 中我添加了:
<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_product_view>
<reference name="content">
<reference name="product.info">
<block type="reports/product_viewed" name="product.recently.viewed" as="product_recently_viewed" template="reports/product_viewed.phtml"/>
<block type="poll/activePoll" name="right.poll" after="product_recently_viewed">
<action method="setPollTemplate"><template>poll/active.phtml</template><type>poll</type></action>
<action method="setPollTemplate"><template>poll/result.phtml</template><type>results</type></action>
</block>
</reference>
</reference>
</catalog_product_view>
和
<?php echo $this->getChildHtml('product_recently_viewed'); ?>
在view.phtml,但我还是一无所获。 我查看了mysql里面的table,里面有最后浏览过的商品的记录。所以我的问题是,是什么让我错了?有什么想法吗?
尝试使用 local.xml 文件中的 xml 代码:
<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_product_view>
<reference name="product.info">
<block type="reports/product_viewed" name="product.recently.viewed" as="product_recently_viewed" template="reports/product_viewed.phtml"/>
<block type="poll/activePoll" name="right.poll" after="product_recently_viewed">
<action method="setPollTemplate"><template>poll/active.phtml</template><type>poll</type></action>
<action method="setPollTemplate"><template>poll/result.phtml</template><type>results</type></action>
</block>
</reference>
</catalog_product_view>
</layout>
这是因为您不需要嵌套引用即可在模板中注入内容。如果这不起作用,那么唯一的原因就是您在 catalog.xml 文件中没有 product.info
句柄,因为大多数主题都自定义了它。您需要检查主题的 catalog.xml。
对于您显示的 PHP 代码,块不是这样调用的。 getSingleton
方法保留用于以单例方式加载模型。但是,您使用完全限定的 class 名称传递它的方式,无论如何您都可能获得该块的对象。请记住它以备将来参考。块在需要时通过 Magento 的布局模型实例化。它们应该以这种方式使用。
你已经使用了 getSingleton 尝试使用这个:
<?php $_recentlyViewed =
Mage::getModel('Mage_Reports_Block_Product_Viewed')-> getItemsCollection(); ?>
<?php foreach ($_recentlyViewed as $_recentlyProduct): ?>
<?php var_dump($_recentlyProduct); ?>
<?php endforeach; ?>
通过使用getModel,我认为你的工作可以实现