Last active
August 10, 2016 13:48
-
-
Save Tomasz-Silpion/5c050bdc590dec21d6d4ed5baa567574 to your computer and use it in GitHub Desktop.
Count customers email domain occurences from Magento orders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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