Magento Paggination problem in magento 1.4.1
Bookmark on del.icio.us
Tweet
Tweet
I have to say that the stable version of magento 1.4.1 is not that stable!!
Please release the CE version with checking the unimplemented methods in the core code.
I have found and solve the problem of toolbars display error for the new magento 1.4.1
first of all, for more developers if you want to see the errors prints in the frontend without checking errors using a reference number
do the following in the SSH or use your ftp.
cd errors/
cp local.xml.sample ./local.xmlwhich means you can just rename the local.xml.sample to local.xml to make all the error message print in the frondend.Now you may have the errors for the toolbar pager as most of CE user will have their custom theme and the 1.3.2 and older all follow the same theme structure but in 1.4.0+ they change the toolbar class
Mage_Catalog_Block_Product_List_Toolbar extends Mage_Core_Block_Templatewhich used to be
class Mage_Catalog_Block_Product_List_Toolbar extends Mage_Page_Block_Html_Pagerbut now they add a mothed to show the pager which listing the pages in Mage_Catalog_Block_Product_List_Toolbar the toolbar.phtml there is code
<?php echo $this->getPagerHtml() ?>which call this method
/**
* Render pagination HTML
*
* @return string
*/
public function getPagerHtml()
{
$pagerBlock = $this->getChild('product_list_toolbar_pager');
if (
$pagerBlock instanceof Varien_Object) {
/* @var $pagerBlock Mage_Page_Block_Html_Pager */
$pagerBlock->setAvailableLimit($this->getAvailableLimit());
$pagerBlock->setUseContainer(false)
->setShowPerPage(false)
->setShowAmounts(false)
->setLimitVarName($this->getLimitVarName())
->setPageVarName($this->getPageVarName())
->setLimit($this->getLimit())
->setFrameLength(Mage::getStoreConfig('design/pagination/pagination_frame'))
->setJump(Mage::getStoreConfig('design/pagination/pagination_frame_skip'))
->setCollection($this->getCollection());
return
$pagerBlock->toHtml();
}
return '';
}but they have not implement the method of setUseContainer(false) and setShowAmounts(false)
to solve this problem first you need to add a child to toolbar which is too simple in their release note saying “In layout of any custom theme the usage of catalog/product_list_toolbar block should be changed to page/html_pager:
1) Replace the catalog/product/list/toolbar.phtml of your theme by the new one
2) Update catalog.xml layout: <block type=”catalog/product_list_toolbar” name=”product_list_toolbar” template=”catalog/product/list/toolbar.phtml”> should be replaced into <block type=”page/html_pager” name=”product_list_toolbar_pager”/> “
the correct way should be add this to the catalog.xml
to solve this problem first you need to add a child to toolbar which is too simple in their release note saying “In layout of any custom theme the usage of catalog/product_list_toolbar block should be changed to page/html_pager:
1) Replace the catalog/product/list/toolbar.phtml of your theme by the new one
2) Update catalog.xml layout: <block type=”catalog/product_list_toolbar” name=”product_list_toolbar” template=”catalog/product/list/toolbar.phtml”> should be replaced into <block type=”page/html_pager” name=”product_list_toolbar_pager”/> “
the correct way should be add this to the catalog.xml
<catalog_category_default>
<!-- <reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
</reference> -->
<reference name="content">
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<!-- The following code shows how to set your own pager increments -->
<!--
<action method="setDefaultListPerPage"><limit>4</limit></action>
<action method="setDefaultGridPerPage"><limit>9</limit></action>
<action method="addPagerLimit"><mode>list</mode><limit>2</limit></action>
<action method="addPagerLimit"><mode>list</mode><limit>4</limit></action>
<action method="addPagerLimit"><mode>list</mode><limit>6</limit></action>
<action method="addPagerLimit"><mode>list</mode><limit>8</limit></action>
<action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action>
-->
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</block>
</reference>
</catalog_category_default>there is 2 place to add <block type=”page/html_pager” name=”product_list_toolbar_pager”/> within the <block type=”catalog/product_list_toolbar” name=”product_list_toolbar” template=”catalog/product/list/toolbar.phtml”>
which can make it as a child of toolbar otherwise you can’t call method of getChild in the toolbar.php
after that you may need to add the method to page/html/pager.php which i will hack the core code as I can handle all the update and even though make a local overwrite class is better but I don’t want any more update as they release all the errors “stable” version I will have to check everything after updated so I prefer hard code it.
which can make it as a child of toolbar otherwise you can’t call method of getChild in the toolbar.php
after that you may need to add the method to page/html/pager.php which i will hack the core code as I can handle all the update and even though make a local overwrite class is better but I don’t want any more update as they release all the errors “stable” version I will have to check everything after updated so I prefer hard code it.
class Mage_Page_Block_Html_Pager extends Mage_Core_Block_Template
{
protected $_collection = null;
protected $_pageVarName = 'p';
protected $_limitVarName = 'limit';
protected $_availableLimit = array(10=>10,20=>20,50=>50);
protected $_dispersion = 3;
protected $_displayPages = 5;
protected $_showPerPage = true;
protected $_limit = null;
protected $_outputRequired = true;
protected $_showAmount = true; // added attributes
protected $_showContainer = true; //added attributesand at the end of the file add
public function setShowAmounts($varName)
{
$this->_showAmount = $varName;
return $this;
}
public function getShowAmounts()
{
return $this->_showAmount;
}
public function setUseContainer($varName)
{
$this->_showContainer = $varName;
return $this;
}
public function getShowContainer()
{
return $this->_showContainer;
}then you still need to change the pager.phtml file
*
* @see Mage_Page_Block_Html_Pager
*/
?>
<?php if($this->getCollection()->getSize()): ?>
<?php if($this->getShowContainer()): ?>
<div class="pager"> <!-- this is the container -->
<?php endif; ?>
<?php if($this->getShowAmounts()): ?>
<p class="amount"> <!-- this is the show amounts-->
<?php if($this->getLastPageNum()>1): ?>
<?php echo $this->__('Items %s to %s of %s total', $this->getFirstNum(), $this->getLastNum(), $this->getTotalNum()) ?>
<?php else: ?>
<?php echo $this->__('%s Item(s)', $this->getTotalNum()) ?>
<?php endif; ?>
</p>
<?php endif; ?>
<?php
if($this->getShowPerPage()): ?>
<fieldset class="limiter">
<label><?php echo $this->__('Show') ?></label>
<select onchange="setLocation(this.value)">
<?php foreach ($this->getAvailableLimit() as $_key=>$_limit): ?>
<option value="<?php echo $this->getLimitUrl($_key) ?>"<?php if($this->isLimitCurrent($_key)): ?> selected="selected"<?php endif ?>>
<?php echo $_limit ?>
</option>
<?php endforeach; ?>
</select> <?php echo $this->__('per page') ?>
</fieldset>
<?php endif ?>
<?php
if($this->getLastPageNum()>1): ?>
<div 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/back.png') ?>" alt="<?php echo $this->__('Previous Page') ?>" class="v-middle" /></a></li>
<?php endif ?>
<?php foreach ($this->getPages() as $_page): ?>
<?php if ($this->isPageCurrent($_page)): ?>
<li><span class="current"><?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/next.png') ?>" alt="<?php echo $this->__('Next Page') ?>" class="v-middle" /></a></li>
<?php endif ?>
</ol>
</div>
<?php endif; ?>
<?php if($this->getShowContainer()): ?>
</div>
<?php endif; ?>
<?php endif; ?>
No comments yet.