0
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
    <block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>

The above represents the pagination of a product collection. It displays page size, products per page, current (and next, previous, etc) page, sort action, etc. Normally i'd call this with a getChild( ) call.

Now, how can I recreate the above function call in something like a widget? Where I must use other methods than the layout.xml and getChild calls to generate blocks.

For example:

$this->_pager = $this->getLayout()
    ->createBlock('catalog/product_list_toolbar')->setTemplate('catalog/product/list/toolbar.phtml');

This accomplishes the first part of the block/template call.

and:

$this->_pager = $this->getLayout()
    ->createBlock('page/html_pager', 'product_list_toolbar_pager');

This accomplishes the second part of the block/template call.

How can I combine these two related pieces of functionality? I need to return them with a toHtml( ) function call.

  • What are you trying to accomplish? Product collection pagination and related display is terribly bungled and coupled in Magento 1, and recreating this functionality is problematic at best. – benmarks Feb 25 '15 at 18:03
  • @benmarks display product collection pagination for a custom product collection within a widget. Using 'only' the first part makes a call to the second part using getchild( ), which, if you've worked with widgets, doesn't really work. If I only use the second part then the sorting toolbar section is left out. My only functioning workaround is to take the 'guts' of each and put them together within the widget itself. – easymoden00b Feb 25 '15 at 18:15
  • I assume you're wanting to do this in a widget because you want an admin interface with some input(s) which will be used to define the params of the product collection? – benmarks Feb 25 '15 at 19:13
  • @benmarks bingo. We're generating a cms page for every category, sale, new products, other_random_things, etc. page and this widget will take parameters from the cms page to retrieve custom product collections. – easymoden00b Feb 25 '15 at 19:25
1

I'm pretty sure that you can get what you need by looking at the new products widget (Mage_Catalog_Block_Product_Widget_New). All you need to do is setProductCollection() with a collection of your choosing.

  • awesome, but the layered navigation now is not functional. – easymoden00b Mar 2 '15 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.