Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Count customers email domain occurences from Magento orders
<?php
require_once('app/Mage.php');
umask(0);
Mage::app();
$emails = array();
$orders = Mage::getModel('sales/order')->getCollection();
foreach ($orders as $order) {
$emails[] = $order->getCustomerEmail();
}
$domains = array();
foreach ($emails as $email) {
$domain = substr(strrchr($email, "@"), 1);
$domains[$email] = $domain;
}
$total = count($domains);
$occurences = array_count_values($domains);
arsort($occurences);
foreach ($occurences as $domain => $count) {
$percent = round(($count / $total) * 100, 2);
echo "$domain ($count) - $percent%<br/>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.