1

When I use the below code for updating store credit balance to customer, I am getting this error:

Fatal Error: Call to a member function setCustomer() on boolean in

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

$balance->save();
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Kaushik Dey
  • 77
  • 1
  • 8

3 Answers3

1

It seems the code Mage::getModel('enterprise_customerbalance/balance') returns false.

Please, verify if you have the Enterprise_CustomerBalance_Model_Balance class.

Maybe you are trying to use the code of Magento Enterprise Edition for Magento Community Edition.

If you watch the value of $className in the method getModelInstance of the Mage_Core_Model_Config class. It returns the 'Mage_Enterprise_Customerbalance_Model_Balance' value in Magento Community Edition. There is no such class and the function Mage::getModel('enterprise_customerbalance/balance') returns false.

You may try to check the edition with the code (it should work if the Magento Community version >= 1.7) - Mage::getEdition()

  • Thanks for the response. I am using magento 1.9 community edition. is their any other module so that I can use. – Kaushik Dey Nov 06 '17 at 12:53
  • @KaushikDey There is no such module in the Core of Magento Community Edition. Maybe some of the extensions below has the functionality you need: Amasty - Store Credit, Magestore - Magento Store Credit extension, Mageworx - Magento Loyalty Booster extension v2.9.3 – Aleks Mitskevich Nov 09 '17 at 10:22
0

Make sure this model class (or its parent) has a method named setCustomer()

Share model Code to get further advice. Normally class constructors don't return boolean.

Vladimir Samsonov
  • 1,344
  • 2
  • 11
  • 18
  • Thanks for the reply, I just found that code from here [link](https://stackoverflow.com/questions/17040183/how-do-i-update-customer-store-credit-programmatically). I am not sure which model you want to see ? – Kaushik Dey Oct 31 '17 at 13:19
0

after some code review here you are:

$balance = Mage::getModel('enterprise_customerbalance/balance')
            ->setCustomerId($customer->getId())
            ->setWebsiteId($websiteId)
            ->loadByCustomer();

$balance->setAmountDelta($anyNumber)
    ->setUpdatedActionAdditionalInfo($data['comment'])
    ->setHistoryAction(1)
    ->save();
Vladimir Samsonov
  • 1,344
  • 2
  • 11
  • 18