Kaushik Dey
Kaushik Dey

Reputation: 77

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

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();

Upvotes: 1

Views: 2604

Answers (3)

Aleks Mitskevich
Aleks Mitskevich

Reputation: 96

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()

Upvotes: 1

Vladimir Samsonov
Vladimir Samsonov

Reputation: 1329

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();

Upvotes: 0

Vladimir Samsonov
Vladimir Samsonov

Reputation: 1329

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.

Upvotes: 0

Related Questions