Last active
August 19, 2020 12:31
-
-
Save sanbornm/6541304 to your computer and use it in GitHub Desktop.
Get store credit and rewards points balance for all Magento customers, export to csv
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('default'); | |
setlocale(LC_MONETARY, 'en_US'); | |
$customers = Mage::getModel('customer/customer')->getCollection(); | |
$count = 0; | |
foreach ($customers as $customer) { | |
$line = implode(',', array( | |
$customer->getId(), | |
$customer->getEmail(), | |
number_format(getStoreCreditBalance($customer), 2, '.', ''), | |
getRewardsPointsBalance($customer) | |
)). "\n"; | |
file_put_contents("customer-balances.csv", $line, FILE_APPEND); | |
$count = $count + 1; | |
if ($count > 100000000000) { | |
break; | |
} | |
} | |
function getRewardsPointsBalance($customer) | |
{ | |
$rewardpoints = Mage::getModel('enterprise_reward/reward') | |
->setCustomer($customer) | |
->setWebsiteId(Mage::app()->getWebsite()->getId()) | |
->loadByCustomer() | |
->getCurrencyAmount(); | |
return (int) $rewardpoints; | |
} | |
function getStoreCreditBalance($customer) | |
{ | |
$customerId = $customer->getId(); | |
$websiteId = 1; | |
$balanceModel = Mage::getModel('enterprise_customerbalance/balance') | |
->setCustomerId($customerId) | |
->setWebsiteId($websiteId) | |
->loadByCustomer(); | |
// check if balance found | |
if (!$balanceModel->getId()) { | |
return (float) 0; | |
} | |
return (float) $balanceModel->getAmount(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment