Magento : Invalid argument supplied for foreach in toolbar.phtml on line 63

Friday, 18. November 2011

Invalid argument supplied for foreach in toolbar.phtml is a common error abserved mostly when upgrading from very old versions of Magento notably 1.3 and below to latest versions.

Here are steps to follow in order to solve the problem.

1. Create Template file for Pagination

Create a new file called pager.phtml in the /template/catalog/product/list/ folder inside your theme folder and add this code.

<?php if($this->getCollection()->getSize()): ?>
        <?php if($this->getLastPageNum()>1): ?>
        <td class="pages">
            <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 Page'); ?>" /></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 Page'); ?>" /></a></li>
            <?php endif ?>
            </ol>
        </td>
        <?php endif; ?>
<?php endif ?>

2. Now open file catalog.xml

Locate and edit the file catalog.xml from your theme’s layout folder. Search for this line of code:

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

Add this line underneath.

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

2. Now open file toolbar.phtml

Finally locate the file toolbar.phtml from your theme/template/catalog/product/list/. Now search for the below block of code approximately around lines 42 – 63:

<?php if($this->getLastPageNum()>1 && is_array($this->getPages())): ?>
...
...
...
<?php endif; ?>

Now replace this block of code with the following code:

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

Enjoy!

Magento SEO & Catalog Sitemap | How to enable magento catalog sitemap for your store and why it is important

Thursday, 4. August 2011

Most of you may already know the importance of Sitemaps on your store but for those who are new to the subject, sitemaps in brief helps search engines locate useful information about your store (or website) easily. Sitemaps helps with SEO for your site. They are important, among other things I should say, in getting you up to the search pages.

Now we know, in brief atleast, what sitemaps are and why you need them, the question is now how do I enable sitemaps on my Magento store.

Well, wonder no more! In Magento there are two types of sitemaps that you can enable (or create).

A] Catalog Sitemap

This is the sitemap that maps all your catalog in a structure that’s easy for crawlers to absorb!

There are two types of Catalog sitemaps that you can enable one being, category sitemap and the other product sitemap.

Category Sitemap

http://www.yourdomain.com/catalog/seo_sitemap/category/

Product Sitemap

http://www.yourdomain.com/catalog/seo_sitemap/product/

A] Google (XML) Sitemap

You can also enable the Google XML sitemap for your site which in conjunction with the robots.txt file, can work a treat for your site as as major search engines are concerned.

To enable Google sitemap:

Navigate to – System > Configuration > Catalog > Google Sitemap. Enable all the options.

Here you can enable the sitemap and set up frequencies in which the file will be generated.

To add the actual file and generate it:
Navigate to – Catalog > Google Sitemap. Press the Add New Sitemap button. Specify the location and name of the file.

Save and Generate.