I'm working with Magento ver. 1.9.1.1. and I need to update store credit balance for a customer. I know that it's possible to do it in Magento admin interface, but in my case I need to do an HTTP request to a server and actually do the same manipulations as we can do via Magento admin interface.
On the internet I found a code which allows to create a Credit Memo. Does I have to create a credit Memo to update customer store credit balance or it's not necessary?
Does someone has any idea how to do it?
I appreciate any answers. Thank you.
Try this
$balance = Mage::getModel('enterprise_customerbalance/balance')
->setCustomer($customer)
->setWebsiteId($websiteId)
->setAmountDelta($anyNumber)
->setComment($data['comment']);
$balance->save();
take more look at function customerSaveAfter() in observer of customerBalance module
This will work perfectly
$balance = Mage::getModel('enterprise_customerbalance/balance');
$balance->setCustomerId($customer_id)
->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
->loadByCustomer();
$current_balance = $balance->getAmount();
$comment = 'This is a comment that will appear in the credit update history';
// add store credit
$balance->setAmount($current_balance);
$balance->setAmountDelta($amount_to_be_added);
$balance->setUpdatedActionAdditionalInfo($comment);
$balance->setHistoryAction(1); // 1= updated
$balance->save();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With