0

ここにある Mostviewed を追加しようとしています:

App/code/local/Mage/Catalog/Block/Product/Mostviewed.php

次のコードを追加しました。

class Mage_Catalog_Block_Product_Mostviewed extends Mage_Catalog_Block_Product_Abstract
{
   public function __construct(){
        parent::__construct();
        $storeId = Mage::app()->getStore()->getId();
        $collection = Mage::getResourceModel('reports/product_collection')
        ->addViewsCount();
        $collection->getSelect()->joinInner(array('e2' => 'catalog_product_flat_'.$storeId), 'e2.entity_id = e.entity_id');
        $this->setProductCollection($collection);
        return parent::_beforeToHtml();
    }
}

ここに追加されましecho $this->getToolbarHtml()た:

app/design/frontend/default/default/template/catalog/product/mostviewedlist.phtml

ページネーションを表示できませんmostviewedlist.phtml.

誰かがこの問題を解決するのを手伝ってくれますか?

どんな助けでも大歓迎です。

4

1 に答える 1

0

ブロックは次のようになります。

class Mage_Catalog_Block_Product_Mostviewed extends Mage_Catalog_Block_Product_Abstract
{
    public function __construct(){
        parent::__construct();
        $storeId = Mage::app()->getStore()->getId();
        $collection = Mage::getResourceModel('reports/product_collection')
            ->addViewsCount();
        $collection->getSelect()->joinInner(array('e2' => 'catalog_product_flat_'.$storeId), 'e2.entity_id = e.entity_id');
        $this->setProductCollection($collection);
    }

    protected function _prepareLayout()
    {
        parent::_prepareLayout();

        $pager = $this->getLayout()->createBlock('page/html_pager', 'mostview.pager')
                      ->setCollection($this->getProductCollection());
        $this->setChild('pager', $pager);
        $this->getProductCollection()->load();

        return $this;
    }

    public function getPagerHtml()
    {
        return $this->getChildHtml('pager');
    }
}

テンプレートは次のようになります。

<?php $_collection = $this->getProductCollection(); ?>

<!-- top pagination -->
<?php echo $this->getPagerHtml(); ?>

<?php if($_collection->getSize()): ?>
    ...
    <?php foreach ($_collection as $_item): ?>
       ...
    <?php endforeach; ?>
<?php endif ?>

<!-- bottom pagination -->
<?php echo $this->getPagerHtml(); ?>

ツールバーを表示したい場合。ブロックは次のようになります: (注: このコードはテストしていません)

class Mage_Catalog_Block_Product_Mostviewed extends Mage_Catalog_Block_Product_Abstract
{
    public function __construct(){
        parent::__construct();
        $storeId = Mage::app()->getStore()->getId();
        $collection = Mage::getResourceModel('reports/product_collection')
            ->addViewsCount();
        $collection->getSelect()->joinInner(array('e2' => 'catalog_product_flat_'.$storeId), 'e2.entity_id = e.entity_id');
        $this->setProductCollection($collection);
    }

    protected function _prepareLayout()
    {
        parent::_prepareLayout();

        $toolbar = $this->getLayout()->createBlock('catalog/product_list_toolbar', microtime())
            ->setCollection($this->getProductCollection());

        $pager = $this->getLayout()->createBlock('page/html_pager', microtime());
        $toolbar->setChild('product_list_toolbar_pager', $pager);

        $this->setChild('toolbar', $toolbar);
        $this->getProductCollection()->load();

        return $this;
    }

    public function getPagerHtml()
    {
        return $this->getChildHtml('toolbar');
    }
}
于 2013-05-08T16:28:07.537 に答える