Search code examples
phpmagentobraintree

Fatal error: Call to a member function deleteCustomer() on a non-object in


I'm new to PHP and Magento, I'm trying to delete a Customer from Magento and I get this error -

Fatal error: Call to a member function deleteCustomer() on a non-object in /home/c42gor/public_html/app/code/local/Braintree/controllers/CustomerController.php on line 30

At other times I get -

Fatal error: Call to a member function deleteCustomer() on a non-object in /home/c42gor/public_html/app/code/local/Braintree/controllers/CustomerController.php on line 15

The CustomerController.php file contains this code -

<?php

require('Mage/Adminhtml/controllers/CustomerController.php');

class Braintree_CustomerController extends Mage_Adminhtml_CustomerController
{

    public function deleteAction()
    {
        $braintree = Mage::getModel('braintree/paymentMethod');
        $customerId = $this->getRequest()->getParam('id');

        if ($customerId)
        {
            $braintree->deleteCustomer($customerId);
        }

        parent::deleteAction();
    }

    public function massDeleteAction()
   {
        $customerIds = $this->getRequest()->getParam('customer');

        if(is_array($customerIds))
        {
            $braintree = Mage::getModel('braintree/paymentMethod');
            foreach ($customerIds as $customerId)
            {
                $braintree->deleteCustomer($customerId);
            }
        }

        parent::massDeleteAction();
    }
}

Solution

  • Change

    $braintree = Mage::getModel('braintree/paymentMethod');
    

    To

    $braintree = Mage::getModel('braintree/paymentmethod');
    

    Then rename

    /app/code/local/Braintree/{Modulename}/Model/PaymentMethod.php
    

    To

     /app/code/local/Braintree/{Modulename}/Model/Paymentmethod.php
    

    Then change the class name by edit file /app/code/local/Braintree/{Modulename}/Model/Paymentmethod.php

    Change

      class Braintree_{Modulename}_Model_PaymentMethod ...
    

    To

      class Braintree_{Modulename}_Model_Paymentmethod ...