I am new to php/magento to for warn you. I am making a script to grab some quick info. I am using magento 1.7.0.2. This script works fine until the telephone number is empty and then it stops. It is in a php file. see anything?
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
$collection = Mage::getModel('customer/customer')->getCollection();
$sz=$collection->getSize();
echo "$sz total customers</br>";
$count=0;
echo '<table cellpadding="5"> ';
echo '<tr>';
echo '<td> </td><td>ID </td><td>Qty </td><td>Name </td><td> Email</td> <td> Phone</td>';
echo '</tr>';
foreach ($collection as $user){
$orders = Mage::getModel('sales/order')
->getCollection()
->addFieldToSelect('increment_id')
->addFieldToFilter('customer_id',$user->getId());
if($orders->getSize() >= 5){
$u=Mage::getModel('customer/customer')->load($user->getId());
$tmpID=$u->getId();
$name=$u->getName();
$email=$u->getEmail();
$phone='NA';
//$pri;
$ordercount=$orders->getSize();
try{
$phone=$u->getPrimaryBillingAddress()->getTelephone();
}
catch(Exception $e){
echo $e->errorMessage();
$phone='NA';
}
$count++;
echo '<tr>';
echo "<td> $count </td>";
echo "<td> $tmpID </td>";
echo "<td> $ordercount </td>";
echo "<td> $name </td>";
echo "<td> $email </td>";
echo "<td> $phone </td>";
echo '</tr>';
//echo "$count-ID: $tmpID Number Of Orders: $ordercount $name $email $phone </br>";
}
}
echo '</table>';
?>