Cannot extent class (extended class not found)

Discussion in 'aMember Pro v.4' started by bfritton, Jan 14, 2013.

  1. bfritton

    bfritton Certified aMember Developer

    Joined:
    Oct 26, 2009
    Messages:
    54
    Hi all,
    I'm developing a new plugin which makes some changes to the way to which the authorize.net plugin stores credit cards (adding functionality to send CIM tokens to another system).

    However, after many hours of trying different things, I still cannot get my plugin's class to extend the core authorize-cim plugin so that aMember will use my storeCard() method instead of the core plugins.

    Here's what the latest version of class extension, saved in application/magento/library/PaymentMethod.php looks like:

    PHP:
    class Magento_PaymentMethod extends Am_Paysystem_AuthorizeCim
    {
        public function 
    storeCreditCard(CcRecord $ccAm_Paysystem_Result $result)
        {
    I've also tried extending Am_Controller_CreditCard's updateAction() method (used when a user updates their saved credit card profile) and that presents the same problem where I get an error saying that the core class (the class being extended) does not exist, which obviously it does.

    For example:
    PHP:
    PHP Fatal error:  Class 'Am_Paysystem_AuthorizeCim' not found in /var/www/amember/application/cc/plugins/authorize-cim-magento.php on line 4
    I've also tried both of these method overrides through site.php as well as creating a new payment plugin which just extended the authorize-cim extension and had the one method that I needed to change in it. I looked for an event that I could observe but there is none when that update credit card action takes place.

    Any help with why aMember keeps thinking that those classes don't exist when I extend them?
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    I believe the problem is simple.
    These classes are not included if plugin is not enabled. So there are two solutions:
    1. Include these classes from your plugin code.
    Or, the better way:
    2. Copy all necessary code from classes which you need to your classes.
  3. bfritton

    bfritton Certified aMember Developer

    Joined:
    Oct 26, 2009
    Messages:
    54
    Hi Alex,
    I have the Authorize.net CIM (authorize-cim) plugin enabled. If I debug using my IDE, I can get to a breakpoint in the Paysystem controller and that controller then turns its attention to the StoreCreditCard() method that I need to modify.

    I don't think that copying all of a class' code instead of just the method in question into my plugin file is going to help as its a pretty standard thing to go about overriding only a few methods in a class by means of extending that class. There is something funky going on.

    I am almost at the point of simply modifying the core plugin file itself and renaming it something different but then I would loose the ability to automatically take advantage of any updates, fixes or improvements to the core plugin.... and this should just work :)

    Any help? Thank you.
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Ok. May be authorize-cim plugin is being initialized after your plugin. So class is not exists when you try to use it.
    Try to use something like this before using Am_Paysystem_AuthorizeCim
    PHP:
    if(!class_exists('Am_Paysystem_AuthorizeCim'false)){
    Am_Di::getInstance()->plugins_payment->load('authorize-cim');
    }
  5. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Or may be use something like this (just before your class):
    PHP:
    require_once APPLICATION_PATH '/cc/plugins/authorize-cim.php';
  6. bfritton

    bfritton Certified aMember Developer

    Joined:
    Oct 26, 2009
    Messages:
    54
    Haven't had time to try this yet, will soon!
  7. bfritton

    bfritton Certified aMember Developer

    Joined:
    Oct 26, 2009
    Messages:
    54
    Alex, this still doesn't work even with your suggestions.

    I tried overriding a class method in library/Am/Form and got the same result. The php file that holds the extending class gets loaded, the include statement gets run but the method which I'm overriding never gets hit, the application always goes back to the file and method that is being extended. My IDE even says I'm extending the class.

    PLEASE help with this - it is a crippling blog to my use of aMember that it seems it just locks out all customization like this.

    The class being extended is /library/Am/Form/Brick.php's Am_Form_Brick_Product.

    The file extending that is /application/Magento/library/Am/Form/Brick.php and my class and the first part of the overriding method are pasted below. In this case, I'm trying to override only one method in that class.

    PHP:
    <?php
    /**
    * Override of product brick builder to stop all billing
    * plans from being returned, only the default billing plan should
    * be available to the public signup forms
    */
    include ROOT_DIR.'/library/Am/Form/Brick.php';
    class 
    Magento_Am_Form_Brick_Product extends Am_Form_Brick_Product
    {
        public function 
    insertBrick(HTML_QuickForm2_Container $form)
        {
            
    $name self::$bricksAdded 'product_id_' self::$bricksAdded 'product_id';
            
    self::$bricksAdded++;
    .....
  8. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Lets shedule a chat session in Skype for monday, and I hope we will get all resolved. cgicentral_alex

Share This Page