skip to Main Content

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

3

Answers


  1. 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.

    Login or Signup to reply.
  2. 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();
    
    Login or Signup to reply.
  3. 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()

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search