How can I programmatically update credit for clients

I work with Magento ver. 1.9.1.1. and I need to update the store’s credit balance for the customer. I know that this can be done in the Magento admin interface, but in my case I need to make an HTTP request to the server and actually perform the same manipulations as we do using the Magento admin interface.

On the Internet, I found a code that allows you to create a credit memo. Do I have to create a credit memo to update the credit balance of a customer store or is it not necessary?

Does anyone know how to do this?

I appreciate any answers. Thanks.

+4
source share
2 answers

try it

$balance = Mage::getModel('enterprise_customerbalance/balance') ->setCustomer($customer) ->setWebsiteId($websiteId) ->setAmountDelta($anyNumber) ->setComment($data['comment']); $balance->save(); 

we’ll take a closer look at the customerSaveAfter () function in the customerBalance module observer.

+6
source

That works great

 $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(); 
+4
source

Source: https://habr.com/ru/post/1485579/


All Articles