0

商品を紹介するスクリプトを作りました。

ただし、すべての製品は、ページ番号ツールバーなしで 1 つのページに表示されます

製品コレクションのページ番号を有効にする方法を教えてください。

以下を使用してコレクションを受け取ります。

$attribute = Mage::getResourceModel('catalog/product')->getAttribute('manufacturer');
$attribute->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID);
$source = $attribute->getSource();
$id = $source->getOptionId($brand);

//$products = Mage::getModel('catalog/product')->getCollection();
$products = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes());
$products->addAttributeToFilter('manufacturer', array('eq' => $id));

次に、catalog/list.phtml からコピーした foreach を使用して、すべての製品を表示します

ページ番号ツールバーをアクティブにする方法

4

2 に答える 2

1

これを試して:

$pager = $this->getLayout()->createBlock('page/html_pager');
echo $this->getLayout()->createBlock('catalog/product_list_toolbar')->setChild('product_list_toolbar_pager', $pager)->setCollection($products)->toHtml();
于 2013-10-18T15:08:11.530 に答える
0

catalog/product/list.phtmlそこからコピーする代わりに、を使用する必要があります。したがって、これを の<global>-tag 内に含める必要がありますconfig.xml

    <blocks>
        <yourmodule>
            <class>Namespace_Yourmodule_Block</class>
        </yourmodule>
    </blocks>

これを後でレイアウト XML に追加できます。

<yourmodule_index_view translate="label">
    <!-- other nodes here, for example root where you pick base page layout template -->
    <reference name="content">
        <!-- more blocks here or below if you need anything above or below listing -->
        <block type="yourmodule/list" name="anyName" template="catalog/product/list.phtml"/>
    </reference>
</yourmodule_index_view>

そしてコントローラーでIndexController.php

public function viewAction() {
    $this->loadLayout();
    $this->renderLayout();
}

そしてあなたのブロックPHPBlock/List.php

class Namespace_Yourmodule_Block_List extends Mage_Catalog_Block_Product_List
{
    protected function _getProductCollection()
    {
        // any code here, get the collection in $collection for example..
        $this->_productCollection = $collection;
        return $this->_productCollection;
    }
}
于 2013-10-18T14:37:54.790 に答える