如何获取最近在Magento查看客户用户的产品

时间:2013-03-28 12:59:36

标签: magento

当我想为访客用户显示最新产品时遇到一个问题,有没有办法向访客用户显示最近查看产品,

Magento支持最近为注册用户查看产品但对于访客用户如何显示最近查看该特定访客的产品...

我在等待您的回应,

希望我能得到一些回复。

提前致谢。

3 个答案:

答案 0 :(得分:2)

这里是phtml

<?php if ($_products = $this->getRecentlyViewedProducts()):
$ids = '';
foreach ($_products as $_item) {
    $ids .= $_item->getId() . ';';
}
?>
<div class="lftHeading">
<span
        style="text-transform:capitalize;background:url(<?php echo $this->getSkinUrl('css/images/clo_left_heading_bullet2.gif') ?>) top left no-repeat;"
        >recently viewed</span>
</div>
<div class="innerRgtMenu recently_viewed_block">
<table id="recently-viewed-items">
    <?php $i = 0; foreach ($_products as $_item): if ($i == 3) {
    continue;
} ?>
    <?php $product = $_item ?>
    <tr>
        <td><a style="border:1px solid #DDDDDD;float:left;margin:5px;padding:5px;"
               href="<?php echo $this->getProductUrl($_item, array('_nosid' => true)) ?>" class="product-image"><img
                src="<?php echo $this->helper('catalog/image')->init($product, 'thumbnail')->resize(50) ?>"
                width="50" alt="<?php echo $this->escapeHtml($_item->getName()) ?>"/></a></td>
        <td><a style="position:relative;top:3px;font-size:11px;"
               href="<?php echo $this->getProductUrl($_item, array('_nosid' => true)) ?>"><?php echo $this->escapeHtml($_item->getName()) ?></a>
        </td>

    </tr>
    <?php $i++;
endforeach; ?>
</table>
<div style="margin: 5px 0px 5px 2px; text-align: center; width: 140px;">
    <input type="button" class="button recently_viewed_btn" value="<?php echo $this->__('Email These To Me') ?> "
           onClick="email_recently('<?php echo $ids; ?>')"/>
</div>
<div style="margin:5px;">
    <a href="<?php echo $this->getBaseUrl() ?>recently-viewed-items/"><?php echo $this->__('See All Recently Viewed') ?></a>
</div>
<script type="text/javascript">decorateList('recently-viewed-items');</script>

和php文件

class Mage_Reports_Block_Product_Viewed extends Mage_Reports_Block_Product_Abstract
{
const XML_PATH_RECENTLY_VIEWED_COUNT    = 'catalog/recently_products/viewed_count';

/**
 * Viewed Product Index model name
 *
 * @var string
 */
protected $_indexName       = 'reports/product_index_viewed';

/**
 * Retrieve page size (count)
 *
 * @return int
 */
public function getPageSize()
{
    if ($this->hasData('page_size')) {
        return $this->getData('page_size');
    }
    return Mage::getStoreConfig(self::XML_PATH_RECENTLY_VIEWED_COUNT);
}

/**
 * Added predefined ids support
 */
public function getCount()
{
    $ids = $this->getProductIds();
    if (!empty($ids)) {
        return count($ids);
    }
    return parent::getCount();
}

/**
 * Prepare to html
 * check has viewed products
 *
 * @return string
 */
protected function _toHtml()
{
    if (!$this->getCount()) {
        return '';
    }
    $this->setRecentlyViewedProducts($this->getItemsCollection());
    return parent::_toHtml();
}
}

如果它不适用于访客 - 尝试将php文件中的最后一个功能更改为

   protected function _toHtml()
{
 /*   if ($this->_hasViewedProductsBefore() === false) {
        return '';
    } */

    $this->setDisplayMinimalPrice('1');
    $collection = $this->_getRecentProductsCollection();

    $hasProducts = (bool)count($collection);
//        if (is_null($this->_hasViewedProductsBefore())) {
//           Mage::getSingleton('reports/session')->setData('viewed_products', $hasProducts);
//        }
    if ($hasProducts) {
        $this->setRecentlyViewedProducts($collection);
    }

    return parent::_toHtml();
}

答案 1 :(得分:2)

阻止最近浏览的产品在magento 1.6-1.9.2.2中没有任何代码修改工作正常 如果未显示块,则需要检查:

  1. 阻止已正确添加到可见容器中的页面(默认阻止添加到右侧边栏)
  2. 日志已启用。检查系统 - &gt;配置 - &gt;系统 - &gt;日志选项“启用日志”=是
  3. 重建索引“类别产品”(catalog_category_product)

答案 2 :(得分:0)

据我所知 - 它应该适合客人。至少它在我的网站上运行 这是我把它放在页面上的方式:

<block type="reports/product_viewed" name="reports.product.recently.viewed" template="reports/recently_viewed.phtml" />