Custom Redirect Plugin Stopped Working

Discussion in 'Integration' started by lee_campbell, Nov 17, 2016.

  1. lee_campbell

    lee_campbell New Member

    Joined:
    Dec 9, 2013
    Messages:
    3
    Currently, our team has a custom redirect plugin setup on aMember.

    The plugin is active and we are able to set the url on aMember admin side, however the redirect is not happening.

    This is our plugin:


    PHP:
    <?php
    class Am_Plugin_ThanksRedirect extends Am_Plugin
    {
        function 
    onGridProductInitForm(Am_Event_Grid $event)
        {
            
    $event->getGrid()->getForm()->getAdditionalFieldSet()->addText('_thanks_redirect_url', array('class' => 'el-wide'))
                ->
    setLabel(array(
                    
    ___("After Purchase Redirect User to this URL\ninstead of thanks page")
                    ));
           
        }
        function 
    onGridProductValuesFromForm(Am_Event_Grid $event)
        {
            
    $args $event->getArgs();
            
    $product $args[1];
            
    $product->data()->set('thanks_redirect_url', @$args[0]['_thanks_redirect_url']);
        }
        function 
    onGridProductValuesToForm(Am_Event_Grid $event)
        {
            
    $args $event->getArgs();
            
    $product $args[1];
            
    $args[0]['_thanks_redirect_url'] = $product->data()->get('thanks_redirect_url');
        }
        function 
    onThanksPage(Am_Event $event)
        {
            if(!
    $event->getInvoice()) return;
            
    $url null;
            foreach (
    $event->getInvoice()->getProducts() as $pr)
                if (
    $url $pr->data()->get('thanks_redirect_url'))
                    break;
            
    $t = new Am_SimpleTemplate();
            
    $t->assign('invoice'$event->getInvoice());
            
    $t->assign('user'$event->getInvoice()->getUser());
            
    $url $t->render($url);
            if (
    $url)
                
    $event->getController()->redirectLocation($url);
        }
    }
    Its almost like the onThanksPage event is not being called as it goes to our confirmation page.

    Is there a problem with out event?
  2. jenolan

    jenolan aMember Coder

    Joined:
    Nov 3, 2006
    Messages:
    510
    Looks right though the current official plugin does
    PHP:
                Am_Mvc_Response::redirectLocation($url);
    caesar likes this.
  3. lee_campbell

    lee_campbell New Member

    Joined:
    Dec 9, 2013
    Messages:
    3
    Is there anything that needs to be added in the site.php as well for the onThanksPage event to fire?

    We have also tried using:


    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::THANKS_PAGE, function (Am_Event $event){
      
            
    /* @var $di Am_Di */
        
    $di $event->getDi();
        
    /* @var $invoice Invoice */
        
    $invoice $event->getInvoice();
        if(!
    $invoice) return;
        
    $controller $event->getController();

        
    $url null;

            foreach (
    $event->getInvoice()->getProducts() as $pr) {
                if (
    $url $pr->data()->get('thanks_redirect_url')) {
                    break;
                }
            }

            
    $t = new Am_SimpleTemplate();
            
    $t->assign('invoice'$event->getInvoice());
            
    $t->assign('user'$event->getInvoice()->getUser());
            
    $url $t->render($url);
            if (
    $url) {
                
    Am_Mvc_Response::redirectLocation($url);
                
    $event->getController()->redirectLocation($url);
            }
      
    });
    As recommended here: https://www.amember.com/docs/How_to_redirect_user_to_different_thanks_page_after_payment
    Last edited: Nov 21, 2016
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    It is not necessary to add anything to site.php if you already use thank-redirect plugin.
  5. lee_campbell

    lee_campbell New Member

    Joined:
    Dec 9, 2013
    Messages:
    3
    Is there another thank-plugin we need?

    Our custom plugin is named thanks-plugin, however that is what we named it.
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Do you have any issue with current setup? Do you mind to contact us in helpdesk?
    https://www.amember.com/support
    We will help to resolve it as soon as possible.

    Best Regards.

Share This Page