Skip to content

Instantly share code, notes, and snippets.

@devjosh12
Created May 26, 2015 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devjosh12/29da959bcbeea358e604 to your computer and use it in GitHub Desktop.
Save devjosh12/29da959bcbeea358e604 to your computer and use it in GitHub Desktop.
Add Pagination to custom product collection
<?php $_items = $this->getItems() ?>
<?php
$_convertedFinalPrice="";
if (($_items = $this->getItems()) && $_items->getSize()): ?>
<div class="category-products">
<?php echo $this->getToolbarHtml() ?>
<?php echo $this->getPagerHtml(); ?>
<?php $_collectionSize = $_items->count();
//echo $_collectionSize; ?>
<?php $_columnCount = 3; ?>
<?php $i=0; foreach ($_items as $_item): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<?php
$base_price= $_item->getPrice();
$final_price= $_item->getFinalPrice();
if($base_price > $final_price) {?>
<div class="offer-box" style="top: 21px; display: inline-block ! important; float: left; left: 10%;">
<span style="padding-left:8px;">
<?php $special_percent = ceil(100 - (( 100/$base_price ) * $final_price ));
echo $special_percent.'%';?>
</span>
</div>
<?php } ?>
<a href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_item, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(136, 215); ?>" width="136" height="215" alt="<?php echo $this->stripTags($this->getImageLabel($_item, 'small_image'), null, true) ?>" /></a>
<h2 class="product-name"><a href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>"><?php echo $this->htmlEscape($_item->getName()) ?></a></h2>
<?php if($_item->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_item, 'short') ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($_item, true) ?>
<?php $_store = $_item->getStore();
$_taxHelper = $this->helper('tax'); ?>
<?php $_convertedPrice = $_store->roundPrice($_store->convertPrice($_item->getPrice())); ?>
<?php $_price = $_taxHelper->getPrice($_item, $_convertedPrice); ?>
<?php $_finalPrice = $_taxHelper->getPrice($_item, $_convertedFinalPrice) ?>
<?php $weightArr=explode(" ",$_item->getWeights());
if(isset($weightArr['0']))
{
$weight_v=$weightArr['0'];
if (strpos($weight_v, ".") !== false) {
$weight=$weight_v;
}
else{
$weight=preg_replace("/[^0-9]/","",$_item->getWeights());
}
$unit=ltrim(preg_replace("/[0-9]/","",$_item->getWeights()),".");
}
else
{
$weight=0;
$unit='Kg';
}
?>
<?php
if($weight>0)
{
?>
<div class="product-banner" style="margin-top:0px;width:100%;border:none;">
<div class="per-you">
<div class="per-kg"><span class="WebRupee"> Rs.</span> <?php echo number_format($_price/$weight, '2', '.', ','); ?>/<?php echo $unit?>
</div>
</div>
</div>
<?php } ?>
<?php /*WDCA CODE BEGINS*/ ?>
<?php if(!Mage::getStoreConfigFlag('advanced/modules_disable_output/TBT_Rewards') && Mage::getConfig()->getModuleConfig('TBT_Rewards')->is('active', 'true')) : ?>
<?php $predict_points_block = Mage::getBlockSingleton('rewards/product_predictpoints')?>
<?php $predict_points_block->setProduct($_item);?>
<?php echo $predict_points_block->toHtml()?>
<?php endif; ?>
<?php /*WDCA CODE ENDS*/ ?>
<div class="actions">
<?php if($_item->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_item) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_item) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_item)): ?>
<li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?>
</ul>
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<div class="toolbar-bottom">
<?php echo $this->getPagerHtml(); ?>
<?php echo $this->getToolbarHtml() ?>
</div>
</div>
<?php endif; ?>
<script type="text/javascript">
//<![CDATA[
windowLoadedFlag = false;
window.onload = function () {
windowLoadedFlag = true;
};
var jQueryWaiter = function () {
var functions = [];
var timer = function() {
if(typeof window.jQuery != 'undefined') {
while (functions.length) {
functions.shift()(window.jQuery);
}
} else {
window.setTimeout(timer, 100);
}
};
timer();
return {
execute: function(onJQueryReady) {
if (window.jQuery) {
onJQueryReady(window.jQuery);
} else {
functions.push(onJQueryReady);
}
}
};
}();
window.SgyIAS = {
debug: false,
_log: function(object) {
if(this.debug) {
console.log(object);
}
},
init: function(){
jQuery.getScript("http://mahesh/pets2015/js/jquery/infinitescroll/jquery-ias.min.js", function() {
jQuery(function($) {
var config = {
item: '.products-grid',
container : '.category-products',
next: '.next',
pagination: '.pager',
delay: 600,
negativeMargin: 150,
history: {
prev: '.prev'
},
noneleft: {
text: '<em>You\'ve reached the end page.</em>',
html: '<div class="ias-noneleft" style="text-align: center;">{text}</div>'
},
spinner: {
src: 'http://mahesh/pets2015/skin/frontend/default/petsworld/images/ajax-loader.gif',
html: '<div class="ias-spinner" style="text-align: center;"><img style="display:inline" src="{src}"/> <em>Loading the next page...</em></div>'
},
trigger: {
text: 'Load more items',
html: '<div class="ias-trigger ias-trigger-next" style="text-align: center; cursor: pointer;"><a>{text}</a></div>',
textPrev: 'Load more items',
htmlPrev: '<div class="ias-trigger ias-trigger-prev" style="text-align: center; cursor: pointer;"><a>{text}</a></div>',
offset: 20 }
};
if (window.ias_config){
$.extend(config, window.ias_config);
}
SgyIAS._log({extension: 'ias', config: config});
window.ias = $.ias(config);
SgyIAS._log({extension: 'paging'});
window.ias.extension(new IASPagingExtension());
SgyIAS._log({extension: 'spinner'});
window.ias.extension(new IASSpinnerExtension(config.spinner));
SgyIAS._log({extension: 'noneleft'});
window.ias.extension(new IASNoneLeftExtension(config.noneleft));
SgyIAS._log({extension: 'trigger'});
window.ias.extension(new IASTriggerExtension(config.trigger));
SgyIAS._log({extension: 'history'});
window.ias.extension(new IASHistoryExtension(config.history));
// debug events
window.ias.on('scroll', function(scrollOffset, scrollThreshold){
SgyIAS._log({eventName: 'scroll', scrollOffset: scrollOffset, scrollThreshold: scrollThreshold});
});
window.ias.on('load', function(event){
SgyIAS._log({eventName:'load', event: event});
});
window.ias.on('loaded', function(data, items){
SgyIAS._log({eventName: 'loaded', data: data, items: items});
//alert('loaded');
});
window.ias.on('render', function(items){
SgyIAS._log({eventName: 'render', items: items});
});
window.ias.on('rendered', function(items){
SgyIAS._log({eventName: 'render', items: items});
custome_load_quick_view();// additional function added by mahesh to load the quick view
get_psymb();// additional function added by mahesh to load the for rupee symbole
});
window.ias.on('noneLeft', function(){
SgyIAS._log({eventName: 'noneLeft'});
});
window.ias.on('next', function(url){
SgyIAS._log({eventName: 'next', url: url});
});
window.ias.on('ready', function(){
SgyIAS._log({eventName: 'ready'});
});
$('.toolbar').show();
if(windowLoadedFlag){
$(window).load();
}
SgyIAS._log('Done loading IAS.');
});
});
}
};
jQueryWaiter.execute(function(){
SgyIAS.init();
get_psymb();// for rupee symbole
});
In BLOCK/list.php , Place below code in module
<?php
class Atwix_Cmsattr_Block_List extends Mage_Catalog_Block_Product_Abstract
{
protected $_itemCollection = null;
public function getItems()
{
$brand = $this->getBrand();
$catId= $this->getCategoryid();
if (!$brand)
return false;
if (is_null($this->_itemCollection)) {
$this->_itemCollection = Mage::getModel('atwix_cmsattr/products')->getItemsCollection($brand,$catId);
}
//$pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');
//$pager->setAvailableLimit(array(20=>20));
//$pager->setCollection($this->_itemCollection);
//$this->setChild('pager', $pager);
return $this->_itemCollection;
}
protected function _prepareLayout()
{
parent::_prepareLayout();
$pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');
$pager->setAvailableLimit(array(15=>15,30=>30,45=>45));
$brand = $this->getBrand();
$catId= $this->getCategoryid();
$this->_itemCollection = Mage::getModel('atwix_cmsattr/products')->getItemsCollection($brand,$catId);
$pager->setCollection($this->_itemCollection);
$this->setChild('pager', $pager);
$this->getCollection()->load();
return $this;
}
public function __construct()
{
parent::__construct();
$collection = Mage::getModel('atwix_cmsattr/products')->getItemsCollection();
$this->setCollection($collection);
}
public function getPagerHtml()
{
return $this->getChildHtml('pager');
}
}
//]]>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment