Skip to content

Instantly share code, notes, and snippets.

@Tomasz-Silpion
Last active August 10, 2016 13:48
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 Tomasz-Silpion/5c050bdc590dec21d6d4ed5baa567574 to your computer and use it in GitHub Desktop.
Save Tomasz-Silpion/5c050bdc590dec21d6d4ed5baa567574 to your computer and use it in GitHub Desktop.
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