如何获取最近在Magento中为访客用户查看的产品 [英] How to get Recently View Product For Guest User In Magento

查看:36
本文介绍了如何获取最近在Magento中为访客用户查看的产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想为来宾用户显示最近的产品时,我遇到一个问题,是否有任何方法可以为来宾用户显示最近查看的产品,

I am Facing one problem when i want to display recent products for guest user, is there any ways to show recently view product for guest user,

Magento支持最近为注册用户查看产品,但为来宾用户显示产品如何显示该特定来宾的最近查看产品...

Magento support Recently View Product For Registered User But for Guest User How to show Recently view products by that particular Guest...

我正在等待您的友好答复,

I am waiting for your kind response,

希望我对此有所答复.

提前谢谢.

推荐答案

这是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文件中的最后一个功能更改为

if it will not work for guests - try to change last function in php file to

   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();
}

这篇关于如何获取最近在Magento中为访客用户查看的产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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