cancel
Showing results for 
Search instead for 
Did you mean: 

Add Pagination on my customer page

Add Pagination on my customer page

<?php
function getcustomers() {
	/* Magento's Mage.php path 
	 * Mage Enabler users may skip these lines
	 */
	require_once ("app/Mage.php");
	umask(0);
	Mage::app("default");
	/* Magento's Mage.php path */
	
	/* Get customer model, run a query */
	$collection = Mage::getModel('customer/customer')
				  ->getCollection()
				 // ->addAttributeToSelect('*')
				  ->setPageSize(10);
				  
				  
				  
				   $collection = Mage::getResourceModel('customer/customer_collection')
                ->addNameToSelect()
                ->addAttributeToSelect('email')
                ->addAttributeToSelect('created_at')
                ->addAttributeToSelect('group_id')
                ->joinAttribute('billing_street', 'customer_address/street', 'default_billing', null, 'left')
                ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
                ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
                ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
                ->joinAttribute('billing_fax', 'customer_address/fax', 'default_billing', null, 'left')
                ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
                ->joinAttribute('billing_country_code', 'customer_address/country_id', 'default_billing', null, 'left')
 
                ->joinAttribute('shipping_street', 'customer_address/street', 'default_shipping', null, 'left')
                ->joinAttribute('shipping_postcode', 'customer_address/postcode', 'default_shipping', null, 'left')
                ->joinAttribute('shipping_city', 'customer_address/city', 'default_shipping', null, 'left')
                ->joinAttribute('shipping_telephone', 'customer_address/telephone', 'default_shipping', null, 'left')
                ->joinAttribute('shipping_fax', 'customer_address/fax', 'default_shipping', null, 'left')
                ->joinAttribute('shipping_region', 'customer_address/region', 'default_shipping', null, 'left')
                ->joinAttribute('shipping_country_code', 'customer_address/country_id', 'default_shipping', null, 'left')
                ->joinAttribute('taxvat', 'customer/taxvat', 'entity_id', null, 'left');
				  
	
	$result = array();
	foreach ($collection as $customer) {
		$result[] = $customer->toArray();
	}
	
	return $result;
}
$addressesCollection = Mage::getResourceModel('customer/address_collection');
  $addressesCollection //->addAttributeToSelect('*')
                       ->setPageSize(10);
					   
					   



				       
/* for particular address 
$addressesCollection->addFieldToFilter('id','12'); */
?>
<html>
<head>
<!-- Latest compiled and minified CSS -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">

<!-- jQuery library -->


<!-- Latest compiled JavaScript -->

<title>Company Directory</title>
</head>
<body>

<div> 
<?php  //echo
$this->getLayout()->createBlock('catalogsearch/advanced_form')->setTemplate('catalogsearch/advanced/form.phtml')->toHtml() 
?>
</div>

<div class="table-responsive">
<div class="col-lg-12">
	<br>
	<form action="" method="get" role="search">
		<div class="input-group input-group-lg">
			<input type="text" name="query" class="form-control" placeholder="Search for the company....">
			<span class="input-group-btn">
				<button class="btn btn-primary custom" type="submit"><span class="glyphicon glyphicon-search"></span></button>
				<button type="button" class="btn btn-primary dropdown-toggle custom" data-toggle="dropdown">Industry<span class="caret"></span></button>
				<ul class="dropdown-menu pull-right">
					<li><a href="#">Dietary suppliments</a></li>
					<li><a href="#">Food and Beverage</a></li>
					<li><a href="#">Herbal, Ayurvedic and Homeopathic Suppliments</a></li>
					<li class="divider"></li>
					<li><a href="#">Pets and Veterinary Products</a></li>
					<li><a href="#">Manufacturing and Equipments</a></li>
					<li><a href="#">Formulation Additives</a></li>
				</ul>
			</span>
			<span class="input-group-btn">
				<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">Location<span class="caret"></span></button>
				<ul class="dropdown-menu pull-right">
					<li><a href="#">India</a></li>
					<li><a href="#">USA</a></li>
					<li><a href="#">Australia</a></li>
					<li class="divider"></li>
					<li><a href="#">UK</a></li>
				</ul>
			</span>
		</div>
	</form>
</div>
<div style="clear:both;margin-bottom: 35px;"></div>
<table class="table table-hover">
<tr>
	<td>ID</td>
	<td>Comapny Name</td>
	<td>Email</td>
	<td>Telephone</td>
	<td>Date Created</td>
	<td>Date Updated</td>
</tr>
<?php
foreach ($addressesCollection as $address) {
 
 //print_r($address->getData());

?>

<?php
$result = getcustomers();
if(count($result) > 0){
	foreach($result as $key => $value){
		echo "<tr>";
			echo "<td>".$value['entity_id']."</td>";
			echo "<td>".$value['firstname']."</td>";
			echo "<td>".$value['email']."</td>";
			echo "<td>".$value['billing_telephone']."</td>";
			echo "<td>".$value['created_at']."</td>";
			echo "<td>".$value['updated_at']."</td>";
		echo "</tr>";
	}
}else{
	echo "<tr><td colspan=\"7\">No records found</td></tr>";
}
}
?>
</table>
<?php $collection->getSelect()->limit(2)->setCurPage(1); ?>
<nav>
  <ul class="pagination">
    <li>
      <a href="#" aria-label="Previous">
        <span aria-hidden="true">&laquo;</span>
      </a>
    </li>
    <li><a href="#">1</a></li>
    <li><a href="#">2</a></li>
    <li><a href="#">3</a></li>
    <li><a href="#">4</a></li>
    <li><a href="#">5</a></li>
	<li><a href="#">....</a></li>
	<li><a href="#">50125</a></li>
    <li>
      <a href="#" aria-label="Next">
        <span aria-hidden="true">&raquo;</span>
      </a>
    </li>
  </ul>
</nav>
</div>
<style>
.custom{
    -webkit-border-radius: 0px !important;
    -moz-border-radius: 0px !important;
    border-radius: 0px !important;
}
</style>
</body>
</html>

This is the code now print all customer but I want a pagination and Search function for customer search Can any body help me to do that please.

Check the url

http://dietaryglobal.com/index.php/directory/

4 REPLIES 4

Re: Add Pagination on my customer page

Hi,

 

Thanks for your reply..

 

When I use this code it showing error...

Fatal error: Using $this when not in object context in /home/dietaryglobal/public_html/app/design/frontend/default/ma_veneno/template/dbi/customer.phtml on line 44

 

$custom_collection = Mage::getModel('devins_module/entity')->getCollection();
$pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');
$pager->setAvailableLimit(array(15=>15));
$pager->setCollection($custom_collection);
echo $pager;

 

Re: Add Pagination on my customer page

Hi,

 

Please help me some one.

 

 

Thanks 

Re: Add Pagination on my customer page

Hello, please replace "$this" with the proper class object. Try with Mage and the error will be solved.

Was my answer helpful? You can accept it as a solution.
175+ Professional Extensions for M1 & M2
Need a developer?Just visit Contact Us Now