Reputation: 578
I made a script witch shows the products.
But all products are on one page without the pagenumber toolbar
How can I activate the pagenumbers for the product collection.
I recieve the collection by using:
$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));
and next I use a foreach coppied from catalog/list.phtml to show all the products
how can I activate the pagenumber toolbar
Upvotes: 0
Views: 58
Reputation: 143
Try this:
$pager = $this->getLayout()->createBlock('page/html_pager');
echo $this->getLayout()->createBlock('catalog/product_list_toolbar')->setChild('product_list_toolbar_pager', $pager)->setCollection($products)->toHtml();
Upvotes: 1
Reputation: 1686
You should use the catalog/product/list.phtml
instead of copying from it. So you need to have this inside the <global>
-tag in your config.xml
:
<blocks>
<yourmodule>
<class>Namespace_Yourmodule_Block</class>
</yourmodule>
</blocks>
You can later add this to your layout 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>
And in the controller IndexController.php
public function viewAction() {
$this->loadLayout();
$this->renderLayout();
}
And your block PHP Block/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;
}
}
Upvotes: 0