Can I programmatically retrieve customers' points balances?

Yes, there are two ways for you to retrieve a customer's points balance through Magento. Please keep in mind, for performance reasons, MageRewards has a Customer Points Balance Indexer which follows Magento's way of handling . This can be found like other indexes under Admin > System > Index Management.


1. Retrieve a customer's points balance through Magento

// Using the customer id
$rewardsCustomer = Mage::getModel('rewards/customer')->load($customerId);

// using a customer object
$customer = Mage::getModel('customer/customer')->load($customerId);
$rewardsCustomer = Mage::getModel('rewards/customer')->getRewardsCustomer($customer);

You can also use these options to get customers' points balances:

  • Get customer's usable points balance - the usable points represents the number of points that can be used by the customer RIGHT NOW. Pending redemptions ARE deducted from this total and pending distributions are NOT added to this total
$rewardsCustomer->getUsablePoints();
  • Get customer's points pending for an event to happen. For example for an order to be invoiced (given MageRewards is configured like this)
$rewardsCustomer->getPendingPoints();
  • Get customer's points that are ON-HOLD
$rewardsCustomer->getOnHoldPoints();
NOTE: It's important to make sure that the Customer Points Balance Indexer is up-to-date, otherwise the points balances will need to be computed which is not that fast especially on big stores (the indexer should be up-to-date if the mode for the index is set to Update on Save).

2. Directly from the DB

You should make sure that the  Customer Points Balance Indexer is up-to-date, before trying to do an export of points balances directly from the DB. The following columns from the rewards_customer_index_points table should be used:


customer_points_usable - the amount of points usable right now by the customer. Pending redemptions ARE deducted from this total and pending distributions are NOT added to this total
customer_points_pending_event - the amount of points pending for an event to happen. For example for an order to be invoiced (given MageRewards is configured like this)
customer_points_pending_approval - the amount of points pending approval


Observation

If you're interested in exporting customers points balances and plan on using direct DB queries, you can run the  Customer Points Balance Indexer directly from the command line before starting the export, exactly like any other Magento Index:

php shell/indexer.php --reindex rewards_transfer

Still need help? Get Help Get Help