Magento: Solution of Warning: Invalid argument supplied for foreach() in …list.phtml

While upgrading Magento, I am getting this error when I go to product list page.

Error:

Warning: Invalid argument supplied for foreach() in …/template/catalog/product/list/toolbar.phtml

Solution:

  • Open layout/catalog.xml
  • Find this:

<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml"> 
  • Just below the above code, add the code below:

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

  • Comment out some lines of code and add a new line of code. It should look like this:


<td class="pages">
    <?php echo $this->getPagerHtml() ?>
    <?php /* ?>
    <strong><?php echo $this->__('Page:') ?></strong>
    <ol>
    <?php if (!$this->isFirstPage()): ?>
        <li><a href="<?php echo $this->getPreviousPageUrl() ?>"><img src="<?php echo $this->getSkinUrl('images/pager_arrow_left.gif') ?>" alt="<?php echo $this->__('Previous') ?>" /></a></li>
    <?php endif ?>
    <?php foreach ($this->getPages() as $_page): ?>
        <?php if ($this->isPageCurrent($_page)): ?>
            <li><span class="on"><?php echo $_page ?></span></li>
        <?php else: ?>
            <li><a href="<?php echo $this->getPageUrl($_page) ?>"><?php echo $_page ?></a></li>
        <?php endif ?>
    <?php endforeach;; ?>
    <?php if (!$this->isLastPage()): ?>
        <li><a href="<?php echo $this->getNextPageUrl() ?>"><img src="<?php echo $this->getSkinUrl('images/pager_arrow_right.gif') ?>" alt="<?php echo $this->__('Next') ?>" /></a></li>
    <?php endif ?>
    </ol>
    <?php */ ?>
</td>

Hope it helps. Thanks.