0

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();
    }
}
  • I should add, the first line - require('Mage/Adminhtml/controllers/CustomerController.php'); - did not have the brackets, I put the brackets as I thought that might have been the problem, but I was wrong the problem still persists. – user2546554 Jul 03 '13 at 12:53
  • $braintree = Mage::getModel('braintree/paymentMethod'); is not returning an object. Try var_dumping it and see what you have – Anigel Jul 03 '13 at 12:53
  • @Anigel - I get - bool(false) – user2546554 Jul 03 '13 at 13:01
  • It is unable to return that object for some reason, you will need to investigate the modules/braintree code to see why it would return false, I've never used braintree so cannot help you really on that score, but my guess would be that it has not been installed or configured properly. – Anigel Jul 03 '13 at 13:12
  • @Anigel Thanks for the advice but as far as I know it has installed and is configured properly, I am able to place orders and all as a customer would do, its just when in the admin panel and I try to delete a customer I get this error, its real frustrating. – user2546554 Jul 03 '13 at 13:23
  • You are trying to call a method function that doesn't exist. What version of magento you are using? – krishna singh Jul 03 '13 at 14:05
  • I am using Magento ver. 1.7.0.2 – user2546554 Jul 03 '13 at 14:10
  • can u share your model methods? – krishna singh Jul 03 '13 at 14:15
  • I actually downloaded the module from magento connect, it is called braintree. Everything seems to be working, just when deleting customer from admin, throws this error. – user2546554 Jul 03 '13 at 14:21
  • let me check with this extension – krishna singh Jul 03 '13 at 14:33

2 Answers2

2

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 ...
MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62
  • I just changed the ('braintree/paymentMethod'); to $braintree = Mage::getModel('braintree/paymentmethod'); and that did the trick. Thanks. – user2546554 Jul 03 '13 at 16:02
  • 1
    It doesn't seem like your module is technically created correctly with the right folder structure, it should be `__Model_PaymentMethod` with path `/app/code/local/Braintree()//` – MagePal Extensions Jul 03 '13 at 16:21
  • I think you are right, this was a module I downloaded from magento connect, it is developed by braintree and they have actually got back to me and said they didn't take into account the case-sensitivity and will fix. – user2546554 Jul 03 '13 at 16:26
  • nice stealing my correct answer which is more than 3 hours old. `$braintree = Mage::getModel('braintree/paymentMethod'); Rename your class to Paymentmethod.php, rename the class label inside the class file accordingly.` – Michael Leiss Jul 03 '13 at 16:52
  • @R.S. i am sorry to have harmed your feelings! next time i will give you a friendly reminder to beg for your upvote! – Michael Leiss Jul 03 '13 at 17:36
0

you shall not use camel case class names like paymentMethod!

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

Rename your class to Paymentmethod.php, rename the class label inside the class file accordingly.

Then do a

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

if the result in the Mage::log is empty you made a mistake with you factory...

Good luck!

Michael Leiss
  • 5,395
  • 3
  • 21
  • 27
  • I renamed the class to Paymentmethod.php so the code looks like this - $braintree = Mage::getModel('braintree/paymentmethod.php'); Mage::log(get_class(braintree)); - but I dont know where the label in the class file is, I looked in paymentmethod.php but I can't find it there. Thanks. – user2546554 Jul 03 '13 at 13:53
  • Mage::getModel('braintree/paymentmethod.php') is nonsense, call it Mage::getModel('braintree/paymentmethod') The Class Name inside the class comes after 'class' inside the Paymentmethod.php file. – Michael Leiss Jul 03 '13 at 14:59
  • You were right I just changed ('braintree/paymentMethod') to ('braintree/paymentmethod') and that fixed it. It turns out magento can be really case-sensitive. Thank you – user2546554 Jul 03 '13 at 15:53