magentocredits

How do I update customer store credit programmatically


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.


Solution

  • 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